From a33579a6671ddfdf4d16b0fa16069634913895ce Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 10 May 2022 11:55:09 +0200 Subject: zshenv: move path_{append,prepend} to utils ...so these can be used in zshrc as well. --- .zsh/utils | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to '.zsh/utils') diff --git a/.zsh/utils b/.zsh/utils index fd81acd..1097637 100644 --- a/.zsh/utils +++ b/.zsh/utils @@ -7,6 +7,30 @@ # # Source repository: git://git.distanz.ch/dotfiles/zsh.git +# prepend custom directory to $PATH +path_prepend() +{ + local dir + for dir; do + case "$PATH" in + "*:${dir}:*"|"${dir}:*"|"*:${dir}") :;; + *) test -d "$dir" && path=("$dir" $path);; + esac + done +} + +# append custom directory to $PATH +path_append() +{ + local dir + for dir; do + case "$PATH" in + "*:${dir}:*"|"${dir}:*"|"*:${dir}") :;; + *) test -d "$dir" && path+="$dir";; + esac + done +} + # are we root? is_root() { test ${EUID:?} -eq 0 -- cgit v1.2.3-54-g00ecf