1
0
mirror of https://github.com/robbyrussell/oh-my-zsh.git synced 2025-12-06 07:20:40 +01:00

feat(last-working-dir): log separate lwds for different SSH keys on the same user account (#9534)

Co-authored-by: Marc Cornellà <hello@mcornella.com>
This commit is contained in:
wilkis
2021-01-12 20:40:27 +01:00
committed by GitHub
parent fae34b383d
commit 869eb20913
2 changed files with 31 additions and 11 deletions

View File

@@ -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: