dotfiles/zsh/func/append_to_path

39 lines
809 B
Bash

# Eryn Wells <eryn@erynwells.me>
# vim:ft=zsh:
append_to_path() {
local should_export_path=1
local should_be_verbose=0
while getopts "ve" opt; do
case $opt in
"e") should_export_path=1;;
"+e") should_export_path=0;;
"v") should_be_verbose=1;;
*) ;;
esac
done
local result=1
local path_to_add=$@[$OPTIND]
if [[ -d "$path_to_add" ]]; then
if (( $should_be_verbose )); then
echo "Appending $path_to_add to \$path"
fi
path+="$path_to_add"
else
if (( $should_be_verbose )); then
echo "$path_to_add doesn't exist"
fi
result=0
fi
if (( $should_export_path )); then
export path
fi
return $result
}
append_to_path "$@"