zoxide/templates/nushell.txt
2021-04-27 17:39:09 +05:30

102 lines
2.6 KiB
Plaintext

{%- let section = "# =============================================================================\n#" -%}
{%- let not_configured = "# -- not configured --" -%}
{{ section }}
# Utility functions for zoxide.
#
# Default prompt for Nushell.
# Taken from: <https://github.com/nushell/nushell/blob/main/docs/sample_config/config.toml>
def __zoxide_prompt [] {
build-string $(ansi gb) $(pwd) $(ansi reset) '(' $(ansi cb) $(do -i { git rev-parse --abbrev-ref HEAD } | str trim) $(ansi reset) ')' $(ansi yb) $(date format '%m/%d/%Y %I:%M:%S%.3f %p') $(ansi reset) '> '
}
{{ section }}
# 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 [] {
zoxide add -- $(pwd)
}
{%- 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 %}
{{ section }}
# 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
} {
cd $(zoxide query --exclude $(pwd) -- $args | str trim)
}
}
} {
cd $(zoxide query --exclude $(pwd) -- $args | str trim)
}
}
{%- if echo %}
echo $(pwd)
{%- endif %}
}
# 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)
{%- if echo %}
echo $(pwd)
{%- endif %}
}
{{ section }}
# 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 %}
{{ not_configured }}
{%- endmatch %}
{{ section }}
# To initialize zoxide, first create a Nushell script:
#
# zoxide init nushell --hook prompt | save ~/.zoxide.nu
#
# Add this to your configuration (usually ~/.config/nu/config.toml):
#
# prompt = "__zoxide_hook;__zoxide_prompt"
# startup = ["zoxide init nushell --hook prompt | save ~/.zoxide.nu", "source ~/.zoxide.nu"]
#
# You can replace __zoxide_prompt with a custom prompt.