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-08-05 08:52:12 +00:00
|
|
|
# Code generated by zoxide. DO NOT EDIT.
|
|
|
|
|
2021-04-27 12:07:38 +00:00
|
|
|
{{ section }}
|
|
|
|
# Utility functions for zoxide.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Default prompt for Nushell.
|
|
|
|
def __zoxide_prompt [] {
|
2021-09-09 14:39:13 +00:00
|
|
|
let git = $'(do -i {git rev-parse --abbrev-ref HEAD} | str trim -rc (char newline))'
|
|
|
|
let git = (if ($git | str length) == 0 { '' } {
|
2021-06-02 21:19:21 +00:00
|
|
|
build-string (char lparen) (ansi cb) $git (ansi reset) (char rparen)
|
|
|
|
})
|
2021-07-11 14:52:07 +00:00
|
|
|
build-string (ansi gb) (pwd) (ansi reset) $git '> '
|
2021-04-27 12:07:38 +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 %}
|
2021-05-03 21:12:43 +00:00
|
|
|
{%- when InitHook::None %}
|
2021-08-31 10:59:57 +00:00
|
|
|
{{ not_configured }}
|
2021-03-31 16:45:43 +00:00
|
|
|
|
2021-05-03 21:12:43 +00:00
|
|
|
{%- when InitHook::Prompt %}
|
2021-03-31 16:45:43 +00:00
|
|
|
def __zoxide_hook [] {
|
2021-09-06 21:11:17 +00:00
|
|
|
shells | where active == $true && name == filesystem | get path | each {
|
|
|
|
zoxide add -- $it
|
|
|
|
}
|
2021-03-31 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 10:59:57 +00:00
|
|
|
# Initialize hook.
|
2021-09-17 20:13:59 +00:00
|
|
|
let-env PROMPT_COMMAND = (
|
|
|
|
let prompt = (if ($nu.env | select PROMPT_COMMAND | empty?) {
|
2021-09-06 21:11:17 +00:00
|
|
|
if ($nu.config | select prompt | empty?) { '__zoxide_prompt' } { $nu.config.prompt }
|
2021-09-17 20:13:59 +00:00
|
|
|
} { $nu.env.PROMPT_COMMAND });
|
2021-09-06 21:11:17 +00:00
|
|
|
if ($prompt | str contains '__zoxide_hook') { $prompt } { $'__zoxide_hook;($prompt)' }
|
|
|
|
)
|
2021-08-31 10:59:57 +00:00
|
|
|
|
2021-05-03 21:12:43 +00:00
|
|
|
{%- when InitHook::Pwd %}
|
2021-07-11 14:52:07 +00:00
|
|
|
$'zoxide: PWD hooks are not supported on Nushell.(char nl)Use (char sq)zoxide init nushell --hook prompt(char sq) instead.(char nl)'
|
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
|
|
|
# When using zoxide with --no-aliases, alias these internal functions as
|
|
|
|
# desired.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Jump to a directory using only keywords.
|
|
|
|
def __zoxide_z [...rest:string] {
|
2021-06-02 21:19:21 +00:00
|
|
|
if (shells | where active == $true | get name) != filesystem {
|
2021-09-03 04:41:42 +00:00
|
|
|
if ($rest | length) > 1 {
|
2021-07-11 14:52:07 +00:00
|
|
|
$'zoxide: can only jump directories on filesystem(char nl)'
|
2021-05-05 23:01:57 +00:00
|
|
|
} {
|
2021-09-03 04:41:42 +00:00
|
|
|
cd $rest
|
2021-05-05 23:01:57 +00:00
|
|
|
{%- if echo %}
|
|
|
|
pwd
|
|
|
|
{%- endif %}
|
|
|
|
}
|
2021-03-31 16:45:43 +00:00
|
|
|
} {
|
2021-09-03 04:41:42 +00:00
|
|
|
let arg0 = ($rest | append '~' | first 1);
|
|
|
|
if ($rest | length) <= 1 && ($arg0 == '-' || ($arg0 | path expand | path exists)) {
|
2021-06-02 21:19:21 +00:00
|
|
|
cd $arg0
|
2021-05-05 23:01:57 +00:00
|
|
|
} {
|
2021-09-09 14:39:13 +00:00
|
|
|
cd $'(zoxide query --exclude (pwd) -- $rest | str trim -rc (char newline))'
|
2021-03-31 16:45:43 +00:00
|
|
|
}
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- if echo %}
|
2021-05-05 23:01:57 +00:00
|
|
|
pwd
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- endif %}
|
2021-05-05 23:01:57 +00:00
|
|
|
}
|
2021-03-31 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Jump to a directory using interactive search.
|
|
|
|
def __zoxide_zi [...rest:string] {
|
2021-06-02 21:19:21 +00:00
|
|
|
if (shells | where active == $true | get name) != filesystem {
|
2021-07-11 14:52:07 +00:00
|
|
|
$'zoxide: can only jump directories on filesystem(char nl)'
|
2021-05-05 23:01:57 +00:00
|
|
|
} {
|
2021-09-09 14:39:13 +00:00
|
|
|
cd $'(zoxide query -i -- $rest | str trim -rc (char newline))'
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- if echo %}
|
2021-05-05 23:01:57 +00:00
|
|
|
pwd
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- endif %}
|
2021-05-05 23:01:57 +00:00
|
|
|
}
|
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) %}
|
|
|
|
|
2021-06-02 21:19:21 +00:00
|
|
|
alias {{cmd}} = __zoxide_z
|
|
|
|
alias {{cmd}}i = __zoxide_zi
|
2021-03-31 16:45:43 +00:00
|
|
|
|
|
|
|
{%- 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-08-05 13:52:13 +00:00
|
|
|
# To initialize zoxide, add this to your configuration (find it by running
|
|
|
|
# `config path` in Nushell):
|
2021-04-27 12:07:38 +00:00
|
|
|
#
|
2021-07-11 14:52:07 +00:00
|
|
|
# startup = ['zoxide init nushell --hook prompt | save ~/.zoxide.nu', 'source ~/.zoxide.nu']
|
2021-04-27 12:07:38 +00:00
|
|
|
#
|
2021-09-17 20:13:59 +00:00
|
|
|
# Note: zoxide only supports Nushell v0.37.0 and above.
|