mirror of
https://github.com/Cian-H/dotfiles.git
synced 2025-12-22 19:31:57 +00:00
Updated zoxide.nu
This commit is contained in:
@@ -6,15 +6,23 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# Initialize hook to add new entries to the database.
|
# Initialize hook to add new entries to the database.
|
||||||
if (not ($env | default false __zoxide_hooked | get __zoxide_hooked)) {
|
export-env {
|
||||||
$env.__zoxide_hooked = 1
|
$env.config = (
|
||||||
$env.config = ($env | default {} config).config
|
$env.config?
|
||||||
$env.config = ($env.config | default {} hooks)
|
| default {}
|
||||||
$env.config = ($env.config | update hooks ($env.config.hooks | default {} env_change))
|
| upsert hooks { default {} }
|
||||||
$env.config = ($env.config | update hooks.env_change ($env.config.hooks.env_change | default [] PWD))
|
| upsert hooks.env_change { default {} }
|
||||||
$env.config = ($env.config | update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append {|_, dir|
|
| upsert hooks.env_change.PWD { default [] }
|
||||||
zoxide add -- $dir
|
)
|
||||||
}))
|
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}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
@@ -23,18 +31,20 @@ if (not ($env | default false __zoxide_hooked | get __zoxide_hooked)) {
|
|||||||
#
|
#
|
||||||
|
|
||||||
# Jump to a directory using only keywords.
|
# Jump to a directory using only keywords.
|
||||||
def --env __zoxide_z [...rest:string] {
|
def --env --wrapped __zoxide_z [...rest: string] {
|
||||||
let arg0 = ($rest | append '~').0
|
let path = match $rest {
|
||||||
let path = if (($rest | length) <= 1) and ($arg0 == '-' or ($arg0 | path expand | path type) == dir) {
|
[] => {'~'},
|
||||||
$arg0
|
[ '-' ] => {'-'},
|
||||||
} else {
|
[ $arg ] if ($arg | path type) == 'dir' => {$arg}
|
||||||
(zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n")
|
_ => {
|
||||||
|
zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cd $path
|
cd $path
|
||||||
}
|
}
|
||||||
|
|
||||||
# Jump to a directory using interactive search.
|
# Jump to a directory using interactive search.
|
||||||
def --env __zoxide_zi [...rest:string] {
|
def --env --wrapped __zoxide_zi [...rest:string] {
|
||||||
cd $'(zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
|
cd $'(zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,8 +53,8 @@ def --env __zoxide_zi [...rest:string] {
|
|||||||
# Commands for zoxide. Disable these using --no-cmd.
|
# Commands for zoxide. Disable these using --no-cmd.
|
||||||
#
|
#
|
||||||
|
|
||||||
alias cd = __zoxide_z
|
alias z = __zoxide_z
|
||||||
alias cdi = __zoxide_zi
|
alias zi = __zoxide_zi
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user