zoxide/templates/nushell.txt

111 lines
3.0 KiB
Plaintext
Raw Normal View History

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