108 lines
3.4 KiB
Plaintext
108 lines
3.4 KiB
Plaintext
{%- let section = "# =============================================================================\n#" -%}
|
|
{%- let not_configured = "# -- not configured --" -%}
|
|
|
|
{%- let pwd_cmd -%}
|
|
{%- if resolve_symlinks -%}
|
|
{%- let pwd_cmd = "pwd -P" -%}
|
|
{%- else -%}
|
|
{%- let pwd_cmd = "pwd -L" -%}
|
|
{%- endif -%}
|
|
|
|
{{ section }}
|
|
# Hook configuration for zoxide.
|
|
#
|
|
{%- if hook != InitHook::None %}
|
|
|
|
# Hook to add new entries to the database.
|
|
{%- if hook == InitHook::Prompt %}
|
|
alias __zoxide_hook 'set __zoxide_hook_pwd = "`{{ pwd_cmd }}`"\
|
|
; if ("$__zoxide_hook_pwd" != "$__zoxide_current_dir") then\
|
|
; set __zoxide_hook_now = `date +%s`\
|
|
; @ __zoxide_hook_elapsed = $__zoxide_hook_now - $__zoxide_entered_at\
|
|
; if ($__zoxide_hook_elapsed >= $__zoxide_rest_threshold && "$__zoxide_current_dir" != "") set __zoxide_last_rested = "$__zoxide_current_dir"\
|
|
; set __zoxide_entered_at = "$__zoxide_hook_now"\
|
|
; set __zoxide_current_dir = "$__zoxide_hook_pwd"\
|
|
; endif\
|
|
; zoxide add -- "$__zoxide_hook_pwd"'
|
|
|
|
{%- else if hook == InitHook::Pwd %}
|
|
set __zoxide_pwd_old = `{{ pwd_cmd }}`
|
|
alias __zoxide_hook 'set __zoxide_pwd_tmp = "`{{ pwd_cmd }}`"\
|
|
; if ("$__zoxide_pwd_tmp" != "$__zoxide_pwd_old") then\
|
|
; set __zoxide_hook_now = `date +%s`\
|
|
; @ __zoxide_hook_elapsed = $__zoxide_hook_now - $__zoxide_entered_at\
|
|
; if ($__zoxide_hook_elapsed >= $__zoxide_rest_threshold && "$__zoxide_current_dir" != "") set __zoxide_last_rested = "$__zoxide_current_dir"\
|
|
; set __zoxide_entered_at = "$__zoxide_hook_now"\
|
|
; set __zoxide_current_dir = "$__zoxide_pwd_tmp"\
|
|
; zoxide add -- "$__zoxide_pwd_tmp"\
|
|
; endif\
|
|
; set __zoxide_pwd_old = "$__zoxide_pwd_tmp"'
|
|
{%- endif %}
|
|
|
|
# Rest tracking for z --.
|
|
if ($?_ZO_REST_THRESHOLD) then
|
|
set __zoxide_rest_threshold = "$_ZO_REST_THRESHOLD"
|
|
else
|
|
set __zoxide_rest_threshold = 5
|
|
endif
|
|
set __zoxide_entered_at = `date +%s`
|
|
set __zoxide_current_dir = `{{ pwd_cmd }}`
|
|
set __zoxide_last_rested = ""
|
|
|
|
# Initialize hook.
|
|
alias precmd ';__zoxide_hook'
|
|
|
|
{%- endif %}
|
|
|
|
{{ section }}
|
|
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
|
#
|
|
|
|
# Jump to a directory using only keywords.
|
|
alias __zoxide_z 'set __zoxide_args = (\!*)\
|
|
if ("$#__zoxide_args" == 0) then\
|
|
cd ~\
|
|
else\
|
|
if ("$#__zoxide_args" == 1 && "$__zoxide_args[1]" == "-") then\
|
|
cd -\
|
|
else if ("$#__zoxide_args" == 1 && "$__zoxide_args[1]" == "--") then\
|
|
if ("$__zoxide_last_rested" != "") then\
|
|
cd "$__zoxide_last_rested"\
|
|
else\
|
|
echo "zoxide: no rested directory found"\
|
|
endif\
|
|
else if ("$#__zoxide_args" == 1 && -d "$__zoxide_args[1]") then\
|
|
cd "$__zoxide_args[1]"\
|
|
else\
|
|
set __zoxide_pwd = `{{ pwd_cmd }}`\
|
|
set __zoxide_result = "`zoxide query --exclude '"'"'$__zoxide_pwd'"'"' -- $__zoxide_args`" && cd "$__zoxide_result"\
|
|
endif\
|
|
endif'
|
|
|
|
# Jump to a directory using interactive search.
|
|
alias __zoxide_zi 'set __zoxide_args = (\!*)\
|
|
set __zoxide_pwd = `{{ pwd_cmd }}`\
|
|
set __zoxide_result = "`zoxide query --exclude '"'"'$__zoxide_pwd'"'"' --interactive -- $__zoxide_args`" && cd "$__zoxide_result"'
|
|
|
|
{{ section }}
|
|
# Commands for zoxide. Disable these using --no-cmd.
|
|
#
|
|
|
|
{%- match cmd %}
|
|
{%- when Some with (cmd) %}
|
|
|
|
alias {{cmd}} __zoxide_z
|
|
alias {{cmd}}i __zoxide_zi
|
|
|
|
{%- when None %}
|
|
|
|
{{ not_configured }}
|
|
|
|
{%- endmatch %}
|
|
|
|
{{ section }}
|
|
# To initialize zoxide, add this to your shell configuration file (usually ~/.tcshrc):
|
|
#
|
|
# zoxide init tcsh > ~/.zoxide.tcsh
|
|
# source ~/.zoxide.tcsh
|