Expand frequent-directory & check dir exists

This commit is contained in:
Kenneth Benzie 2024-04-18 21:59:29 +01:00
parent b9373430b0
commit 0951c445f4

25
zshrc
View File

@ -191,17 +191,22 @@ fi
# Frequntly used directories # Frequntly used directories
function frequent-directory() { function frequent-directory() {
# Replace - with _ in environment variable name. if [ -d "$2" ]; then
local name=$(echo $1 | sed 's/^\(.*\)=.*$/\1/g' | sed 's/-/_/g') # Replace - with _ in environment variable name.
local value=$(echo $1 | sed 's/^.*=\(.*$\)/\1/g') local name=${1//-/_}
export $name=$value local value=$2
hash -d $1 export $name=$value
hash -d $1
fi
} }
frequent-directory Projects="$HOME/Projects" frequent-directory Desktop "$HOME/Desktop"
frequent-directory Sandbox="$HOME/Sandbox" frequent-directory Documents "$HOME/Documents"
frequent-directory config="$HOME/.config" frequent-directory Downloads "$HOME/Downloads"
frequent-directory local="$HOME/.local" frequent-directory Projects "$HOME/Projects"
frequent-directory cache="$HOME/.cache" frequent-directory Sandbox "$HOME/Sandbox"
frequent-directory cache "$HOME/.cache"
frequent-directory config "$HOME/.config"
frequent-directory local "$HOME/.local"
# Load work related config # Load work related config
[ -f ~/.config/work/zshrc ] && source ~/.config/work/zshrc [ -f ~/.config/work/zshrc ] && source ~/.config/work/zshrc