zsh: added auto-saving and auto-loading working dir functionality (may
adjust behavior later to become not automatic)
This commit is contained in:
parent
53d7246381
commit
b0838e8322
1 changed files with 31 additions and 8 deletions
39
.zshrc
39
.zshrc
|
@ -24,6 +24,9 @@
|
||||||
|
|
||||||
export ZINIT_HOME_DIR=""
|
export ZINIT_HOME_DIR=""
|
||||||
|
|
||||||
|
SAVE_WORKING_DIR=true
|
||||||
|
WORKING_DIR_SAVE_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/shell/last-dir.save"
|
||||||
|
|
||||||
# (I know this shouldn't go here, but I needed it to happen early)
|
# (I know this shouldn't go here, but I needed it to happen early)
|
||||||
# change cursor to beam by default
|
# change cursor to beam by default
|
||||||
echo -ne '\e[5 q'
|
echo -ne '\e[5 q'
|
||||||
|
@ -50,6 +53,7 @@
|
||||||
[ -x "$(command -v nvim)" ] && alias vim="nvim" vimdiff="nvim -d"
|
[ -x "$(command -v nvim)" ] && alias vim="nvim" vimdiff="nvim -d"
|
||||||
|
|
||||||
alias vv="$EDITOR"
|
alias vv="$EDITOR"
|
||||||
|
alias sedit="sudoedit"
|
||||||
|
|
||||||
# I do this too much by accident smh my head
|
# I do this too much by accident smh my head
|
||||||
alias :q='exit' \
|
alias :q='exit' \
|
||||||
|
@ -97,7 +101,8 @@
|
||||||
alias \
|
alias \
|
||||||
nvc="(cd ~/.config/nvim/lua/blake && nvim ../../init.lua)" \
|
nvc="(cd ~/.config/nvim/lua/blake && nvim ../../init.lua)" \
|
||||||
zshrc="$EDITOR ~/.zshrc" \
|
zshrc="$EDITOR ~/.zshrc" \
|
||||||
fstab="sudo $EDITOR /etc/fstab" \
|
fstab="sudoedit /etc/fstab" \
|
||||||
|
sedit="sudoedit"
|
||||||
|
|
||||||
# Git cLONE
|
# Git cLONE
|
||||||
alias glone="git clone"
|
alias glone="git clone"
|
||||||
|
@ -538,6 +543,27 @@ bindkey -M vicmd 'k' history-substring-search-up
|
||||||
bindkey -M vicmd 'j' history-substring-search-down
|
bindkey -M vicmd 'j' history-substring-search-down
|
||||||
# <<<
|
# <<<
|
||||||
|
|
||||||
|
# automatically save and resume working directory >>>
|
||||||
|
if $SAVE_WORKING_DIR; then
|
||||||
|
# load the directory (and do validation to make sure it's actually a directory)
|
||||||
|
if test -f "$WORKING_DIR_SAVE_FILE"; then
|
||||||
|
local PREVIOUS_WORKING_DIR="$(cat "$WORKING_DIR_SAVE_FILE")"
|
||||||
|
if test -d "$(cat "$WORKING_DIR_SAVE_FILE")"; then
|
||||||
|
cd "$PREVIOUS_WORKING_DIR" || error $LINENO
|
||||||
|
else
|
||||||
|
echo "Invalid saved working directory ($PREVIOUS_WORKING_DIR)"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Invalid working directory save file ($WORKING_DIR_SAVE_FILE)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
save_working_dir() {
|
||||||
|
$SAVE_WORKING_DIR && pwd > "$WORKING_DIR_SAVE_FILE"
|
||||||
|
}
|
||||||
|
autoload -U add-zsh-hook
|
||||||
|
add-zsh-hook chpwd save_working_dir
|
||||||
|
fi
|
||||||
|
# <<<
|
||||||
# Colors and compinit >>>
|
# Colors and compinit >>>
|
||||||
export LESS_TERMCAP_mb=$'\E[01;32m'
|
export LESS_TERMCAP_mb=$'\E[01;32m'
|
||||||
export LESS_TERMCAP_md=$'\E[01;32m'
|
export LESS_TERMCAP_md=$'\E[01;32m'
|
||||||
|
@ -547,16 +573,13 @@ export LESS_TERMCAP_so=$'\E[01;47;34m'
|
||||||
export LESS_TERMCAP_ue=$'\E[0m'
|
export LESS_TERMCAP_ue=$'\E[0m'
|
||||||
export LESS_TERMCAP_us=$'\E[01;36m'
|
export LESS_TERMCAP_us=$'\E[01;36m'
|
||||||
export LESS=-R
|
export LESS=-R
|
||||||
|
|
||||||
autoload -U compinit colors zcalc
|
autoload -U compinit colors zcalc
|
||||||
compinit -d 2>&1 > /dev/null
|
compinit -d 2>&1 > /dev/null
|
||||||
colors
|
colors
|
||||||
# <<<
|
# <<<
|
||||||
### Various manjaro ZSH functions >>>
|
### Various manjaro ZSH functions >>>
|
||||||
|
# Set terminal window and tab/icon title >>>
|
||||||
# Set terminal window and tab/icon title
|
|
||||||
# usage: title short_tab_title [long_window_title]
|
# usage: title short_tab_title [long_window_title]
|
||||||
# >>>
|
|
||||||
# See: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
|
# See: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
|
||||||
# Fully supports screen and probably most modern xterm and rxvt
|
# Fully supports screen and probably most modern xterm and rxvt
|
||||||
# (In screen, only short_tab_title is used)
|
# (In screen, only short_tab_title is used)
|
||||||
|
@ -594,14 +617,14 @@ function title {
|
||||||
ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" # 15 char left truncated PWD
|
ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" # 15 char left truncated PWD
|
||||||
ZSH_THEME_TERM_TITLE_IDLE="%n@%m:%~"
|
ZSH_THEME_TERM_TITLE_IDLE="%n@%m:%~"
|
||||||
|
|
||||||
# Runs before showing the prompt
|
# Runs before showing the prompt >>>
|
||||||
function mzc_termsupport_precmd {
|
function mzc_termsupport_precmd {
|
||||||
[[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
|
[[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
|
||||||
title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
|
title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
|
||||||
}
|
}
|
||||||
|
# <<<
|
||||||
|
|
||||||
# Runs before executing the command
|
# Runs before executing the command >>>
|
||||||
# >>>
|
|
||||||
function mzc_termsupport_preexec {
|
function mzc_termsupport_preexec {
|
||||||
[[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
|
[[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue