zsh: don't auto load working dir if it has direnv files
Speeds up prompt loading in some cases by preventing loading unneeded folders with direnv
This commit is contained in:
parent
4c13ba7800
commit
397c65c1b7
1 changed files with 24 additions and 2 deletions
22
.zshrc
22
.zshrc
|
@ -245,6 +245,8 @@ load_working_dir() {
|
|||
fi
|
||||
}
|
||||
|
||||
alias lwd=load_working_dir
|
||||
|
||||
SWD_INITIAL_WORKING_DIR="$(pwd)"
|
||||
save_working_dir() {
|
||||
if [ "$(pwd)" != "$SWD_INITIAL_WORKING_DIR" ]; then
|
||||
|
@ -255,8 +257,28 @@ save_working_dir() {
|
|||
autoload -U add-zsh-hook
|
||||
add-zsh-hook chpwd save_working_dir
|
||||
|
||||
# Don't load last working directory if it's a direnv location
|
||||
skip_load=false
|
||||
if [ -e "${XDG_DATA_HOME:-"$HOME/.local/share"}"/direnv/allow ]; then
|
||||
# Avoid direnv slowing down previous working directory
|
||||
working_path="$(cat "$WORKING_DIR_SAVE_FILE" 2> /dev/null || echo -n '/')"
|
||||
if cat "${XDG_DATA_HOME:-"$HOME/.local/share"}"/direnv/allow/* |
|
||||
grep -Po '^.*/' |
|
||||
sed 's_/$__g' |
|
||||
grep -qFf - <(echo "$working_path")
|
||||
then
|
||||
skip_load=true
|
||||
fi
|
||||
fi
|
||||
|
||||
# if we made it to the root directory, then we can assume it's alright to load
|
||||
if [ "$skip_load" = false ]; then
|
||||
# echo "Loading path"
|
||||
# shellchek disable=SC2164
|
||||
load_working_dir && cd - > /dev/null || true
|
||||
else
|
||||
echo "LWD: Skipped loading working dir because of direnv"
|
||||
fi
|
||||
|
||||
# Case insensitive globbing (fix for termux)
|
||||
[ -n "$TERMUX_VERSION" ] && { setopt nocaseglob; zstyle ':completion:*' path-completion true; }
|
||||
|
|
Loading…
Add table
Reference in a new issue