diff options
author | wilkis <git@marv.one> | 2021-01-12 20:40:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-12 20:40:27 +0100 |
commit | 869eb2091389eabd919c32b2ca98ed1b0af851e6 (patch) | |
tree | 025df38a6cfda141e93d968c9f5e728c2e99e5e7 /plugins/last-working-dir/last-working-dir.plugin.zsh | |
parent | fae34b383d6432f7118c2ad082224f6d27d51221 (diff) | |
download | zsh-869eb2091389eabd919c32b2ca98ed1b0af851e6.tar.gz zsh-869eb2091389eabd919c32b2ca98ed1b0af851e6.tar.bz2 zsh-869eb2091389eabd919c32b2ca98ed1b0af851e6.zip |
feat(last-working-dir): log separate `lwd`s for different SSH keys on the same user account (#9534)
Co-authored-by: Marc Cornellà <hello@mcornella.com>
Diffstat (limited to 'plugins/last-working-dir/last-working-dir.plugin.zsh')
-rw-r--r-- | plugins/last-working-dir/last-working-dir.plugin.zsh | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/plugins/last-working-dir/last-working-dir.plugin.zsh b/plugins/last-working-dir/last-working-dir.plugin.zsh index fd21705ae..905a02a70 100644 --- a/plugins/last-working-dir/last-working-dir.plugin.zsh +++ b/plugins/last-working-dir/last-working-dir.plugin.zsh @@ -5,16 +5,18 @@ typeset -g ZSH_LAST_WORKING_DIRECTORY autoload -U add-zsh-hook add-zsh-hook chpwd chpwd_last_working_dir chpwd_last_working_dir() { - if [ "$ZSH_SUBSHELL" = 0 ]; then - local cache_file="$ZSH_CACHE_DIR/last-working-dir" - pwd >| "$cache_file" - fi + # Don't run in subshells + [[ "$ZSH_SUBSHELL" -eq 0 ]] || return 0 + # Add ".$SSH_USER" suffix to cache file if $SSH_USER is set and non-empty + local cache_file="$ZSH_CACHE_DIR/last-working-dir${SSH_USER:+.$SSH_USER}" + pwd >| "$cache_file" } # Changes directory to the last working directory lwd() { - local cache_file="$ZSH_CACHE_DIR/last-working-dir" - [[ -r "$cache_file" ]] && cd "$(cat "$cache_file")" + # Add ".$SSH_USER" suffix to cache file if $SSH_USER is set and non-empty + local cache_file="$ZSH_CACHE_DIR/last-working-dir${SSH_USER:+.$SSH_USER}" + [[ -r "$cache_file" ]] && cd "$(cat "$cache_file")" } # Jump to last directory automatically unless: |