summaryrefslogtreecommitdiff
path: root/plugins/last-working-dir/last-working-dir.plugin.zsh
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2021-01-18 13:16:40 -0700
committerTuowen Zhao <ztuowen@gmail.com>2021-01-18 13:16:40 -0700
commitc6e754a3119b7273a57f0cfed38e85303662d26b (patch)
treec50ae3c6b0271ec88e964d3a57199ea37e63bf0b /plugins/last-working-dir/last-working-dir.plugin.zsh
parentfb45741fc1dbd40dd2be72bc35a28c6ee8f3f7a5 (diff)
parentefcbd9f3480a28ec69c607c46adcbfd8d230ac9f (diff)
downloadzsh-c6e754a3119b7273a57f0cfed38e85303662d26b.tar.gz
zsh-c6e754a3119b7273a57f0cfed38e85303662d26b.tar.bz2
zsh-c6e754a3119b7273a57f0cfed38e85303662d26b.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'plugins/last-working-dir/last-working-dir.plugin.zsh')
-rw-r--r--plugins/last-working-dir/last-working-dir.plugin.zsh14
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: