2021-04-08 18:35:42 +00:00
|
|
|
{%- let section = "# =============================================================================\n#" -%}
|
|
|
|
{%- let not_configured = "# -- not configured --" -%}
|
2021-03-31 16:45:43 +00:00
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2021-03-31 16:45:43 +00:00
|
|
|
# Hook configuration for zoxide.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Hook to add new entries to the database.
|
|
|
|
{%- match hook %}
|
|
|
|
{%- when Hook::None %}
|
|
|
|
def __zoxide_hook [] {}
|
|
|
|
|
|
|
|
{%- when Hook::Prompt %}
|
|
|
|
def __zoxide_hook [] {
|
2021-04-04 14:36:44 +00:00
|
|
|
zoxide add -- $(pwd)
|
2021-03-31 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{%- when Hook::Pwd %}
|
|
|
|
def __zoxide_hook [] {}
|
|
|
|
|
|
|
|
printf "zoxide: PWD hooks are not supported on Nushell.\n Use 'zoxide init nushell --hook prompt' instead.\n"
|
|
|
|
|
|
|
|
{%- endmatch %}
|
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2021-03-31 16:45:43 +00:00
|
|
|
# When using zoxide with --no-aliases, alias these internal functions as
|
|
|
|
# desired.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Jump to a directory using only keywords.
|
|
|
|
def __zoxide_z [...rest:string] {
|
|
|
|
if $(echo $rest | length) == 1 {
|
|
|
|
cd ~
|
|
|
|
} {
|
|
|
|
let args = $(echo $rest | skip 1);
|
|
|
|
if $(echo $args | length) == 1 {
|
|
|
|
let arg0 = $(echo $args | first 1);
|
|
|
|
if $arg0 == '-' {
|
|
|
|
cd -
|
|
|
|
} {
|
|
|
|
if $(echo $arg0 | path exists) {
|
|
|
|
cd $arg0
|
|
|
|
} {
|
2021-04-04 14:36:44 +00:00
|
|
|
cd $(zoxide query --exclude $(pwd) -- $args | str trim)
|
2021-03-31 16:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} {
|
2021-04-04 14:36:44 +00:00
|
|
|
cd $(zoxide query --exclude $(pwd) -- $args | str trim)
|
2021-03-31 16:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- if echo %}
|
2021-03-31 16:45:43 +00:00
|
|
|
echo $(pwd)
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- endif %}
|
2021-03-31 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Jump to a directory using interactive search.
|
|
|
|
def __zoxide_zi [...rest:string] {
|
|
|
|
let args = $(echo $rest | skip 1)
|
|
|
|
cd $(zoxide query -i -- $args | str trim)
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- if echo %}
|
2021-03-31 16:45:43 +00:00
|
|
|
echo $(pwd)
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- endif %}
|
2021-03-31 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2021-03-31 16:45:43 +00:00
|
|
|
# Convenient aliases for zoxide. Disable these using --no-aliases.
|
|
|
|
#
|
|
|
|
|
|
|
|
{%- match cmd %}
|
|
|
|
{%- when Some with (cmd) %}
|
|
|
|
|
|
|
|
alias {{cmd}} = __zoxide_z ''
|
|
|
|
alias {{cmd}}i = __zoxide_zi ''
|
|
|
|
|
|
|
|
{%- when None %}
|
2021-04-08 18:35:42 +00:00
|
|
|
|
|
|
|
{{ not_configured }}
|
2021-03-31 16:45:43 +00:00
|
|
|
|
|
|
|
{%- endmatch %}
|
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2021-03-31 16:45:43 +00:00
|
|
|
# To initialize zoxide with Nushell:
|
|
|
|
#
|
|
|
|
# Initialize zoxide's Nushell script:
|
|
|
|
#
|
|
|
|
# zoxide init nushell --hook prompt | save ~/.zoxide.nu
|
|
|
|
#
|
|
|
|
# Then, in your Nushell configuration file:
|
|
|
|
# - Prepend `__zoxide_hook;` to the `prompt` variable.
|
|
|
|
# - Add the following lines to the `startup` variable:
|
|
|
|
# - `zoxide init nushell --hook prompt | save ~/.zoxide.nu`
|
|
|
|
# - `source ~/.zoxide.nu`
|