nu: more portable zoxide source
no longer hardcodes .config
This commit is contained in:
parent
021e6670d6
commit
6fc13b84e5
@ -713,5 +713,4 @@ $env.config = {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
const zoxide_conf = "~/.config/nushell/zoxide.nu"
|
source zoxide.nu
|
||||||
source $zoxide_conf
|
|
||||||
|
@ -95,6 +95,9 @@ $env.NU_PLUGIN_DIRS = [
|
|||||||
# To load from a custom file you can use:
|
# To load from a custom file you can use:
|
||||||
# source ($nu.default-config-dir | path join 'custom.nu')
|
# source ($nu.default-config-dir | path join 'custom.nu')
|
||||||
|
|
||||||
|
let conf_dir = $nu.config-path | path dirname
|
||||||
|
$env.NU_LIB_DIRS | append conf_dir
|
||||||
|
|
||||||
if (which zoxide | length) > 0 {
|
if (which zoxide | length) > 0 {
|
||||||
zoxide init nushell | save -f ~/.config/nushell/zoxide.nu
|
zoxide init nushell | save -f ([$conf_dir zoxide.nu] | path join)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,60 @@
|
|||||||
# DUMMY FILE for systems that do not have zoxide installed
|
# Code generated by zoxide. DO NOT EDIT.
|
||||||
|
|
||||||
# nu doesn't like sourcing files conditionally, so we can't just have it ignore if zoxide.nu does not exist
|
# =============================================================================
|
||||||
# watch issue: https://github.com/nushell/nushell/issues/8214
|
#
|
||||||
|
# Hook configuration for zoxide.
|
||||||
|
#
|
||||||
|
|
||||||
# zoxide will overwrite this if it exists
|
# Initialize hook to add new entries to the database.
|
||||||
|
if (not ($env | default false __zoxide_hooked | get __zoxide_hooked)) {
|
||||||
|
$env.__zoxide_hooked = true
|
||||||
|
$env.config = ($env | default {} config).config
|
||||||
|
$env.config = ($env.config | default {} hooks)
|
||||||
|
$env.config = ($env.config | update hooks ($env.config.hooks | default {} env_change))
|
||||||
|
$env.config = ($env.config | update hooks.env_change ($env.config.hooks.env_change | default [] PWD))
|
||||||
|
$env.config = ($env.config | update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append {|_, dir|
|
||||||
|
zoxide add -- $dir
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
#
|
||||||
|
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
||||||
|
#
|
||||||
|
|
||||||
|
# Jump to a directory using only keywords.
|
||||||
|
def --env __zoxide_z [...rest:string] {
|
||||||
|
let arg0 = ($rest | append '~').0
|
||||||
|
let path = if (($rest | length) <= 1) and ($arg0 == '-' or ($arg0 | path expand | path type) == dir) {
|
||||||
|
$arg0
|
||||||
|
} else {
|
||||||
|
(zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n")
|
||||||
|
}
|
||||||
|
cd $path
|
||||||
|
}
|
||||||
|
|
||||||
|
# Jump to a directory using interactive search.
|
||||||
|
def --env __zoxide_zi [...rest:string] {
|
||||||
|
cd $'(zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
|
||||||
|
}
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
#
|
||||||
|
# Commands for zoxide. Disable these using --no-cmd.
|
||||||
|
#
|
||||||
|
|
||||||
|
alias z = __zoxide_z
|
||||||
|
alias zi = __zoxide_zi
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
#
|
||||||
|
# Add this to your env file (find it by running `$nu.env-path` in Nushell):
|
||||||
|
#
|
||||||
|
# zoxide init nushell | save -f ~/.zoxide.nu
|
||||||
|
#
|
||||||
|
# Now, add this to the end of your config file (find it by running
|
||||||
|
# `$nu.config-path` in Nushell):
|
||||||
|
#
|
||||||
|
# source ~/.zoxide.nu
|
||||||
|
#
|
||||||
|
# Note: zoxide only supports Nushell v0.89.0+.
|
||||||
|
Loading…
Reference in New Issue
Block a user