Merge pull request #1366 from op/last-working-dir
Added last working directory plugin
Diff
1diff --git a/plugins/last-working-dir/last-working-dir.plugin.zsh b/plugins/last-working-dir/last-working-dir.plugin.zsh
2new file mode 100644
3index 0000000000000000000000000000000000000000..5b3121d11d1992b2377cdf111f1d931a0b570bc1
4--- /dev/null
5+++ b/plugins/last-working-dir/last-working-dir.plugin.zsh
6@@ -0,0 +1,23 @@
7+#!/usr/bin/env zsh
8+# Keeps track of the last used working directory and automatically jumps
9+# into it for new shells.
10+
11+# Flag indicating if we've previously jumped to last directory.
12+typeset -g ZSH_LAST_WORKING_DIRECTORY
13+local cache_file="$ZSH/cache/last-working-dir"
14+
15+# Updates the last directory once directory is changed.
16+function chpwd() {
17+ echo "$PWD" > "$cache_file"
18+}
19+
20+# Changes directory to the last working directory.
21+function lwd() {
22+ [[ ! -r "$cache_file" ]] || cd `cat "$cache_file"`
23+}
24+
25+# Automatically jump to last working directory unless this isn't the first time
26+# this plugin has been loaded.
27+if [[ -z "$ZSH_LAST_WORKING_DIRECTORY" ]]; then
28+ lwd 2>/dev/null && ZSH_LAST_WORKING_DIRECTORY=1 || true
29+fi