mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
[zsh] open new shells in the last working directory
This commit is contained in:
parent
3b6fe44f19
commit
85b179e60d
2 changed files with 35 additions and 3 deletions
|
@ -102,3 +102,26 @@ sudoedit() {
|
|||
}
|
||||
alias sudoe="sudoedit"
|
||||
alias sue="sudoedit"
|
||||
|
||||
# This idea was taken from <https://github.com/ohmyzsh/ohmyzsh/blob/706b2f3765d41bee2853b17724888d1a3f6f00d9/plugins/last-working-dir/last-working-dir.plugin.zsh>
|
||||
SYNC_WORKING_DIR_STORAGE="${ZSH_CACHE_DIR}/last-working-dir"
|
||||
|
||||
autoload -Uz add-zsh-hook
|
||||
add-zsh-hook chpwd sync_working_dir_chpwd_hook
|
||||
sync_working_dir_chpwd_hook() {
|
||||
if [[ "$ZSH_SUBSHELL" == 0 ]]; then
|
||||
sync_working_dir_save
|
||||
fi
|
||||
}
|
||||
|
||||
sync_working_dir_save() {
|
||||
pwd >| "$SYNC_WORKING_DIR_STORAGE"
|
||||
}
|
||||
|
||||
sync_working_dir_load() {
|
||||
local dir
|
||||
if dir="$(<"$SYNC_WORKING_DIR_STORAGE")" 2>/dev/null && [[ -n "$dir" ]]; then
|
||||
cd -- "$dir"
|
||||
fi
|
||||
}
|
||||
alias cds="sync_working_dir_load"
|
||||
|
|
13
zsh/zshrc
13
zsh/zshrc
|
@ -23,14 +23,17 @@ autoload -U colors && colors
|
|||
}
|
||||
|
||||
_perf_timer_stop() {
|
||||
# Record the stop time as precisely as possible even in the case of an error
|
||||
local stop_time="$EPOCHREALTIME"
|
||||
local name="$1"
|
||||
if [[ -z "$name" ]]; then
|
||||
print >&2 "$0: usage: $0 <name>"
|
||||
return 1
|
||||
fi
|
||||
local stop_time="$EPOCHREALTIME" start_time="${_perf_timers[$name]}"
|
||||
local start_time="${_perf_timers[$name]}"
|
||||
unset "_perf_timers[${(qq)name}]"
|
||||
local -i duration="$(( (stop_time - start_time) * 1000 ))"
|
||||
print -- "$(print -P '%F{8}==>%f') ${name}: ${duration}ms"
|
||||
print -r -- "$(print -P '%F{8}==>%f') ${name}: ${duration}ms"
|
||||
}
|
||||
|
||||
# }}}
|
||||
|
@ -58,4 +61,10 @@ done
|
|||
|
||||
_perf_timer_stop "total"
|
||||
|
||||
if [[ -z "$DOTFILES_DISABLE_WELCOME" ]]; then
|
||||
welcome
|
||||
fi
|
||||
|
||||
if [[ -z "$DOTFILES_SYNC_LAST_WORKING_DIR" ]]; then
|
||||
sync_working_dir_load
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue