mirror of
https://github.com/Cian-H/dotfiles.git
synced 2026-04-19 07:25:46 +01:00
Changed . token to _dot
This change allows the dotfiles to work with chezmoi (e.g: on windows) and improves grepability with neovim/telescope
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
some `config.hooks.command_not_found` hooks:
|
||||
- `did_you_mean.nu`: gives a list of 3 external commands that are close to the "not found" one
|
||||
@@ -0,0 +1,57 @@
|
||||
# example:
|
||||
# ```nu
|
||||
# > got
|
||||
# Error: nu::shell::external_command
|
||||
#
|
||||
# × External command failed
|
||||
# ╭─[entry #1:1:1]
|
||||
# 1 │ got
|
||||
# · ─┬─
|
||||
# · ╰── did you mean 'get'?
|
||||
# ╰────
|
||||
# help: No such file or directory (os error 2)
|
||||
#
|
||||
# did you mean?
|
||||
# dot
|
||||
# git
|
||||
# go
|
||||
# ```
|
||||
{|cmd|
|
||||
let commands_in_path = (
|
||||
if ($nu.os-info.name == windows) {
|
||||
$env.Path | each {|directory|
|
||||
if ($directory | path exists) {
|
||||
let cmd_exts = $env.PATHEXT | str downcase | split row ';' | str trim --char .
|
||||
ls $directory | get name | path parse | where {|it| $cmd_exts | any {|ext| $ext == ($it.extension | str downcase)} } | get stem
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$env.PATH | each {|directory|
|
||||
if ($directory | path exists) {
|
||||
ls $directory | get name | path parse | update parent "" | path join
|
||||
}
|
||||
}
|
||||
}
|
||||
| flatten
|
||||
| wrap cmd
|
||||
)
|
||||
|
||||
let closest_commands = (
|
||||
$commands_in_path
|
||||
| insert distance {|it|
|
||||
$it.cmd | str distance $cmd
|
||||
}
|
||||
| uniq
|
||||
| sort-by distance
|
||||
| get cmd
|
||||
| first 3
|
||||
)
|
||||
|
||||
let pretty_commands = (
|
||||
$closest_commands | each {|cmd|
|
||||
$" (ansi {fg: "default" attr: "di"})($cmd)(ansi reset)"
|
||||
}
|
||||
)
|
||||
|
||||
$"\ndid you mean?\n($pretty_commands | str join "\n")"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# you can use the following closure in your config in a few different ways, e.g.
|
||||
#
|
||||
# ```nushell
|
||||
# $env.config.hooks.env_change.PWD = (
|
||||
# $env.config.hooks.env_change.PWD | append (source nu-hooks/nu-hooks/direnv/config.nu)
|
||||
# )
|
||||
# ```
|
||||
#
|
||||
# or
|
||||
#
|
||||
# ```nushell
|
||||
# $env.config.hooks.pre_prompt = (
|
||||
# $env.config.hooks.pre_prompt | append (source nu-hooks/nu-hooks/direnv/config.nu)
|
||||
# )
|
||||
# ```
|
||||
#
|
||||
# > :bulb: **Note**
|
||||
# > the former will update direnv when you enter and leave a directory whereas the later will update
|
||||
# > on every new prompt, i.e. much more often.
|
||||
{ ||
|
||||
if (which direnv | is-empty) {
|
||||
return
|
||||
}
|
||||
|
||||
direnv export json | from json | default {} | load-env
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
def direnv [] {
|
||||
[
|
||||
{
|
||||
condition: {|before, after| ($before != $after) and ($after | path join .env.yaml | path exists) }
|
||||
code: "
|
||||
open .env.yaml | load-env
|
||||
"
|
||||
}
|
||||
{
|
||||
condition: {|before, after| ($before != $after) and ($after | path join '.env' | path exists) }
|
||||
code: "
|
||||
open .env
|
||||
| lines
|
||||
| parse -r '(?P<k>.+?)=(?P<v>.+)'
|
||||
| reduce -f {} {|x, acc| $acc | upsert $x.k $x.v}
|
||||
| load-env
|
||||
"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
export-env {
|
||||
$env.config = ( $env.config | upsert hooks.env_change.PWD { |config|
|
||||
let o = ($config | get -i hooks.env_change.PWD)
|
||||
let val = (direnv)
|
||||
if $o == null {
|
||||
$val
|
||||
} else {
|
||||
$o | append $val
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
def dynamic_load [] {
|
||||
[
|
||||
{
|
||||
condition: {|before, after| (not ('.nu' in (overlay list))) and ('~/.nu' | path exists) }
|
||||
code: "overlay use ~/.nu as .nu"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
export-env {
|
||||
$env.config = ( $env.config | upsert hooks.env_change.PWD { |config|
|
||||
let o = ($config | get -i hooks.env_change.PWD)
|
||||
let val = (dynamic_load)
|
||||
if $o == null {
|
||||
$val
|
||||
} else {
|
||||
$o | append $val
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
# const path = "~/.nu"
|
||||
# const if ($path| path expand | path exists) {
|
||||
# source $path
|
||||
# }
|
||||
@@ -0,0 +1,31 @@
|
||||
# This file configures autojump (https://github.com/wting/autojump) for nushell
|
||||
#
|
||||
# Dependencies
|
||||
# * autojump
|
||||
#
|
||||
# Installation
|
||||
# 1. store in ~/.config/nushell/autojump.nu
|
||||
# 2. add to your config.nu: `source .config/nushell/autojump.nu`
|
||||
#
|
||||
# Usage
|
||||
# Run `j` to jump around
|
||||
|
||||
def autojump_add_to_database [dir] {
|
||||
$env.AUTOJUMP_SOURCED = 1
|
||||
autojump --add $dir
|
||||
}
|
||||
def --env j [dir] {
|
||||
$env.AUTOJUMP_SOURCED = 1
|
||||
cd (autojump $dir)
|
||||
}
|
||||
$env.config = ($env.config | upsert hooks.env_change.PWD {|config|
|
||||
let val = ($config | get -i hooks.env_change.PWD)
|
||||
|
||||
if $val == null {
|
||||
$val | append {|before, after| autojump_add_to_database $after }
|
||||
} else {
|
||||
[
|
||||
{|before, after| autojump_add_to_database $after }
|
||||
]
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,93 @@
|
||||
const NUENV_FILE = ($nu.cache-dir | path join 'nuenv' 'allowed.txt')
|
||||
|
||||
def get-allowed []: [ nothing -> list<string> ] {
|
||||
if ($NUENV_FILE | path exists) {
|
||||
open $NUENV_FILE | lines
|
||||
} else {
|
||||
[]
|
||||
}
|
||||
}
|
||||
|
||||
# setup a hook that will try to load `.env.nu` if it is allowed
|
||||
#
|
||||
# # Example
|
||||
# ```nushell
|
||||
# use nu-hooks/nuenv/hook.nu [ "nuenv allow", "nuenv disallow" ]
|
||||
# $env.config.hooks.env_change.PWD = (use nu-hooks/nuenv/hook.nu; hook setup)
|
||||
# ```
|
||||
export def setup []: [ nothing -> record<condition: closure, code: string> ] {
|
||||
{
|
||||
condition: {|_, after| $after | path join '.env.nu' | path exists }
|
||||
code: $"
|
||||
let allowed = if \('($NUENV_FILE)' | path exists\) {
|
||||
open ($NUENV_FILE) | lines
|
||||
} else {
|
||||
[]
|
||||
}
|
||||
|
||||
if \(open .env.nu | hash sha256\) not-in $allowed {
|
||||
error make --unspanned {
|
||||
msg: $'\(ansi purple\)\('.env.nu' | path expand\)\(ansi reset\) is not allowed',
|
||||
help: $'please run \(ansi default_dimmed\)nuenv allow\(ansi reset\) first',
|
||||
}
|
||||
}
|
||||
|
||||
print $'[\(ansi yellow_bold\)nu-hooks nuenv\(ansi reset\)] loading env file \(ansi purple\).env.nu\(ansi reset\)'
|
||||
source .env.nu
|
||||
"
|
||||
}
|
||||
}
|
||||
|
||||
def _log [msg: string, color: string] {
|
||||
print $'[(ansi $color)nuenv(ansi reset)] (ansi purple)(".env.nu" | path expand)(ansi reset) ($msg)'
|
||||
}
|
||||
|
||||
def warning [msg: string] {
|
||||
_log $msg "yellow_bold"
|
||||
}
|
||||
|
||||
def info [msg: string] {
|
||||
_log $msg "green_bold"
|
||||
}
|
||||
|
||||
def check-env-file [] {
|
||||
if not (".env.nu" | path exists) {
|
||||
error make --unspanned {
|
||||
msg: $"(ansi red_bold)env file not found(ansi reset)",
|
||||
help: $"no (ansi yellow).env.nu(ansi reset) in (ansi purple)(pwd)(ansi reset)",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# adds `./.env.nu` to the list of allowed "env" files
|
||||
export def "nuenv allow" [] {
|
||||
check-env-file
|
||||
|
||||
let allowed = get-allowed
|
||||
|
||||
let hash = open .env.nu | hash sha256
|
||||
if $hash in $allowed {
|
||||
warning "is already allowed"
|
||||
return
|
||||
}
|
||||
|
||||
mkdir ($nu.cache-dir | path join "nuenv")
|
||||
$hash | $in + "\n" out>> $NUENV_FILE
|
||||
info "has been allowed"
|
||||
}
|
||||
|
||||
# removes `./.env.nu` from the list of allowed "env" files
|
||||
export def "nuenv disallow" [] {
|
||||
check-env-file
|
||||
|
||||
let allowed = get-allowed
|
||||
|
||||
let hash = open .env.nu | hash sha256
|
||||
if $hash not-in $allowed {
|
||||
warning "is already disallowed"
|
||||
return
|
||||
}
|
||||
|
||||
$allowed | find --invert $hash | to text | save --force $NUENV_FILE
|
||||
info "has been disallowed"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
# Description
|
||||
#
|
||||
# Include `target/debug` and `target/release` in `$env.PATH`
|
||||
# while `cd`-ing into a Rust project (assumed existence of `Cargo.lock`)
|
||||
#
|
||||
#
|
||||
# Installation
|
||||
#
|
||||
# 1. Move this file under any directory in `$env.NU_LIB_DIRS`
|
||||
# 2. Add `source rusty-paths.nu` to `$nu.config-path`
|
||||
|
||||
|
||||
$env.config = ($env.config | update hooks.env_change.PWD {
|
||||
append {
|
||||
condition: {|_, after| ($after | path join 'Cargo.lock' | path exists) }
|
||||
code: {
|
||||
$env.PATH = (
|
||||
$env.PATH
|
||||
| prepend ($env.PWD | path join 'target/debug')
|
||||
| prepend ($env.PWD | path join 'target/release')
|
||||
| uniq
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
# setup a hook that will log startup times
|
||||
#
|
||||
# # Example
|
||||
# ```nushell
|
||||
# $env.config.hooks.env_change.PWD = (
|
||||
# $env.config.hooks.env_change.PWD | append (
|
||||
# use nu-hooks/startup-times.nu;
|
||||
# startup-times setup
|
||||
# )
|
||||
# )
|
||||
# ```
|
||||
export def setup [
|
||||
dir: path = $nu.data-dir, # the path where to store the "startup times" file
|
||||
]: [ nothing -> closure ] {
|
||||
{|before, _|
|
||||
if $before == null {
|
||||
let file = $dir | path join "startup-times.nuon"
|
||||
if not ($file | path exists) {
|
||||
mkdir ($file | path dirname)
|
||||
touch $file
|
||||
}
|
||||
|
||||
let version = (version)
|
||||
|
||||
# NOTE: this binding is required as per
|
||||
# https://github.com/nushell/nushell/pull/12601#issuecomment-2069167555
|
||||
let startup_times = open $file | append {
|
||||
date: (date now)
|
||||
time: $nu.startup-time
|
||||
build: $version.build_rust_channel
|
||||
allocator: $version.allocator
|
||||
version: $version.version
|
||||
commit: $version.commit_hash
|
||||
build_time: $version.build_time
|
||||
}
|
||||
$startup_times | save --force $file
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
# setup a hook that will activate `toolkit.nu` when found in a directory
|
||||
#
|
||||
# # Example
|
||||
# ```nushell
|
||||
# $env.config.hooks.env_change.PWD = (
|
||||
# $env.config.hooks.env_change.PWD | append (
|
||||
# use nu-hooks/toolkit.nu;
|
||||
# toolkit setup --name "tk" --color "yellow_bold"
|
||||
# )
|
||||
# )
|
||||
# ```
|
||||
export def setup [
|
||||
--name: string = "toolkit", # the name of the overlay, i.e. the command that will be usable
|
||||
--color: string = "yellow_bold", # the color of the "hook" indicator
|
||||
]: [ nothing -> record<condition: closure, code: string> ] {
|
||||
{
|
||||
condition: {|_, after| $after | path join 'toolkit.nu' | path exists }
|
||||
code: $"
|
||||
print $'[\(ansi ($color)\)nu-hooks toolkit\(ansi reset\)] loading \(ansi purple\)toolkit.nu\(ansi reset\) as an overlay'
|
||||
overlay use --prefix toolkit.nu as ($name)
|
||||
"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
name: "nu-hooks"
|
||||
description: "Officially-supported hooks for Nushell"
|
||||
documentation: "https://github.com/nushell/nu_scripts/blob/main/README.md"
|
||||
license: "https://github.com/nushell/nu_scripts/blob/main/LICENSE"
|
||||
version: 0.2.0
|
||||
type: "module"
|
||||
}
|
||||
Reference in New Issue
Block a user