nushell: move to modules/home
Signed-off-by: Bloxx12 <charlie@charlieroot.dev> Change-Id: I6a6a6964b332aee4de78ddbba4d16b55f6783485
This commit is contained in:
parent
71505a4629
commit
8c3ff343b0
10 changed files with 183 additions and 128 deletions
54
modules/home/nushell/zoxide.nu
Normal file
54
modules/home/nushell/zoxide.nu
Normal file
|
@ -0,0 +1,54 @@
|
|||
# Initialize hook to add new entries to the database.
|
||||
export-env {
|
||||
$env.config = (
|
||||
$env.config?
|
||||
| default {}
|
||||
| upsert hooks { default {} }
|
||||
| upsert hooks.env_change { default {} }
|
||||
| upsert hooks.env_change.PWD { default [] }
|
||||
)
|
||||
let __zoxide_hooked = (
|
||||
$env.config.hooks.env_change.PWD | any { try { get __zoxide_hook } catch { false } }
|
||||
)
|
||||
if not $__zoxide_hooked {
|
||||
$env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append {
|
||||
__zoxide_hook: true,
|
||||
code: {|_, dir| zoxide add -- $dir}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
def zoxide_completions [context: string] {
|
||||
let parts = $context | split row " " | skip 1
|
||||
{
|
||||
options: {
|
||||
sort: false,
|
||||
completion_algorithm: substring,
|
||||
case_sensitive: false,
|
||||
},
|
||||
completions: (^zoxide query --list --exclude $env.PWD -- ...$parts | lines | first 10)
|
||||
}
|
||||
}
|
||||
|
||||
# Jump to a directory using only keywords.
|
||||
def --env --wrapped __zoxide_z [...rest: string@zoxide_completions] {
|
||||
let path = match $rest {
|
||||
[] => {'~'},
|
||||
[ '-' ] => {'-'},
|
||||
[ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg}
|
||||
_ => {
|
||||
zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n"
|
||||
}
|
||||
}
|
||||
cd $path
|
||||
}
|
||||
|
||||
# Jump to a directory using interactive search.
|
||||
def --env --wrapped __zoxide_zi [...rest:string] {
|
||||
cd $'(zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
alias z = __zoxide_z
|
||||
alias zi = __zoxide_zi
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue