diff --git a/zsh/func/append_to_path b/zsh/func/append_to_path index 1940855..50fb717 100644 --- a/zsh/func/append_to_path +++ b/zsh/func/append_to_path @@ -3,27 +3,37 @@ append_to_path() { local should_export_path=1 + local verbose=0 - while getopts "e" opt; do + while getopts "ve" opt; do case $opt in "e") should_export_path=1;; "+e") should_export_path=0;; - *) >&2 echo "$0: unknown option '$opt'" + "v") verbose=1;; + *) ;; esac done + local result=1 local path_to_add=$@[$OPTIND] + if [[ -d "$path_to_add" ]]; then - path+="$path_to_add" - - if (( $should_export_path )); then - export path + if (( $verbose )); then + echo "Appending $path_to_add to \$path" fi - - return 1 + path+="$path_to_add" + else + if (( $verbose )); then + echo "$path_to_add doesn't exist" + fi + result=0 fi - return 0 + if (( $should_export_path )); then + export path + fi + + return $result } append_to_path "$@" diff --git a/zsh/func/init_path b/zsh/func/init_path index 40d5d56..8edb939 100644 --- a/zsh/func/init_path +++ b/zsh/func/init_path @@ -1,11 +1,9 @@ # Eryn Wells -# vim:ft=zsh: -autoload -Uz prepend_to_path autoload -Uz append_to_path init_path() { - local should_be_verbose=1 + local should_be_verbose=0 while getopts "v" opt; do case $opt in @@ -15,7 +13,10 @@ init_path() { esac done - export path=() + local verbose_flag + if (( $should_be_verbose )); then + verbose_flag='-v' + fi for p in \ "$HOME/bin" \ @@ -35,13 +36,12 @@ init_path() { "/usr/sbin" \ "/sbin" do - append_to_path +e "$p" - if (( $? && $should_be_verbose )); then - echo $p - fi + append_to_path +e $verbose_flag "$p" done export path rehash } + +init_path "$@" diff --git a/zsh/func/prepend_to_path b/zsh/func/prepend_to_path index 43268e9..efeac1b 100644 --- a/zsh/func/prepend_to_path +++ b/zsh/func/prepend_to_path @@ -1,29 +1,38 @@ # Eryn Wells -# vim:ft=zsh: prepend_to_path() { local should_export_path=1 + local should_be_verbose=0 - while getopts "e" opt; do + while getopts "ve" opt; do case $opt in "e") should_export_path=1;; "+e") should_export_path=0;; - *) >&2 echo "$0: unknown option '$opt'" + "v") should_be_verbose=1;; + *) ;; esac done + local result=1 local path_to_add=$@[$OPTIND] + if [[ -d "$path_to_add" ]]; then - path=("$path_to_add" $path) - - if (( $should_export_path )); then - export path + if (( $verbose )); then + echo "Prepending $path_to_add to \$path" fi - - return 0 + path=("$path_to_add" $path) + else + if (( $verbose )); then + echo "$path_to_add doesn't exist" + fi + result=0 fi - return 1 + if (( $should_export_path )); then + export path + fi + + return $result } prepend_to_path "$@"