Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically jump to last working directory for new shells #1362

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions plugins/last-working-dir/last-working-dir.plugin.zsh
@@ -0,0 +1,23 @@
#!/usr/bin/env zsh
# Keeps track of the last used working directory and automatically jumps
# into it for new shells.

# Flag indicating if we've previously jumped to last directory.
typeset -g ZSH_LAST_WORKING_DIRECTORY

# Updates the last directory once directory is changed.
function cd() {
builtin cd "$@" && echo "$PWD" > "$ZSH/cache/last-working-dir"
}
alias chdir=cd

# Changes directory to the last working directory.
function lwd() {
[[ ! -r ~/.zsh_lwd ]] || builtin cd `cat "$ZSH/cache/last-working-dir"`
}

# Automatically jump to last working directory unless this isn't the first time
# this plugin has been loaded.
if [[ "$ZSH_LAST_WORKING_DIRECTORY" == "" ]]; then
lwd 2>/dev/null && ZSH_LAST_WORKING_DIRECTORY=1 || true
fi