From 3ca89d0e6e7a5996f4bdd968004acc0639e388af Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Tue, 31 Aug 2021 16:28:49 +0530 Subject: [PATCH] Use shell variables instead of env variables --- templates/elvish.txt | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/templates/elvish.txt b/templates/elvish.txt index 4c67b12..25c4f7b 100644 --- a/templates/elvish.txt +++ b/templates/elvish.txt @@ -20,23 +20,21 @@ fn __zoxide_cd [path]{ # Hook configuration for zoxide. # -if (not (and (builtin:has-env __zoxide_hooked) (builtin:eq (builtin:get-env __zoxide_hooked) 1))) { - builtin:set-env __zoxide_hooked 1 +# Initialize hook to track previous directory. +__zoxide_oldpwd = $pwd +before-chdir = [$@before-chdir [_]{ edit:add-var __zoxide_oldpwd $pwd }] - # Initialize hook to track previous directory. - builtin:set-env __zoxide_oldpwd $pwd - before-chdir = [$@before-chdir [_]{ builtin:set-env __zoxide_oldpwd $pwd }] +{#- __zoxide_hooked requires https://github.com/elves/elvish/issues/1395 #} - # Initialize hook to add directories to zoxide. +# Initialize hook to add directories to zoxide. {%- match hook %} {%- when InitHook::None %} - {{ not_configured }} +{{ not_configured }} {%- when InitHook::Prompt %} - edit:before-readline = [$@edit:before-readline []{ zoxide add -- $pwd }] +edit:before-readline = [$@edit:before-readline []{ zoxide add -- $pwd }] {%- when InitHook::Pwd %} - after-chdir = [$@after-chdir [_]{ zoxide add -- $pwd }] +after-chdir = [$@after-chdir [_]{ zoxide add -- $pwd }] {%- endmatch %} -} {{ section }} # When using zoxide with --no-aliases, alias these internal functions as @@ -48,7 +46,7 @@ fn __zoxide_z [@rest]{ if (builtin:eq [] $rest) { __zoxide_cd ~ } elif (builtin:eq [-] $rest) { - __zoxide_cd (builtin:get-env __zoxide_oldpwd) + __zoxide_cd $__zoxide_oldpwd } elif (and ('builtin:==' (builtin:count $rest) 1) (path:is-dir &follow-symlink=$true $rest[0])) { __zoxide_cd $rest[0] } else { @@ -97,4 +95,4 @@ edit:add-var zi~ $__zoxide_zi~ # # eval (zoxide init elvish | slurp) # -# Note that zoxide only supports elvish v0.16.0+. +# Note that zoxide only supports elvish v0.16.0 and above.