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

Added plugin 'last-working-dir' borrowed from omz #545

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions modules/last-working-dir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
last-working-dir
================

This plugin enables your new terminals opened to automatically enter in the last directory worked


Authors
-------

*The authors of this module should be contacted via the [issue tracker][1].*

[1]: https://github.com/sorin-ionescu/prezto/issues

24 changes: 24 additions & 0 deletions modules/last-working-dir/init.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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 chpwd() {
local cache_file="$HOME/.cache/zsh/last-working-dir"
# Use >| in case noclobber is set to avoid "file exists" error
pwd >| "$cache_file"
}

# Changes directory to the last working directory.
function lwd() {
local cache_file="$HOME/.cache/zsh/last-working-dir"
[[ -s "$cache_file" ]] && cd "$(cat "$cache_file")"
}

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