From c05c522f1023d9dd1411fde28600ca7b1ce9f6bc Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 15 Jun 2022 15:28:05 -0500 Subject: Re-indent? --- profile/00_functions.sh | 100 ++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 49 deletions(-) (limited to 'profile') diff --git a/profile/00_functions.sh b/profile/00_functions.sh index a94eaee..3c67ddf 100644 --- a/profile/00_functions.sh +++ b/profile/00_functions.sh @@ -2,61 +2,63 @@ # these should be POSIX-compatible. # add a path to PATH, but only if it's not already there -path_add_to_PATH() { # path_add [-a] PATH... - # -a appends (default is prepend) - APPEND=false - if [ "x$1" = "x-a" ]; then - APPEND=true - shift - fi +path_add_to_PATH() { # path_add_to_PATH [-a] PATH... + # -a appends (default is prepend) + APPEND=false + if [ "x$1" = "x-a" ]; then + APPEND=true + shift + fi - for p; do - case ":$PATH:" in - *:"$p":*) ;; - *) - if $APPEND; then - PATH="$PATH:$p" - else - PATH="$p:$PATH" - fi - ;; - esac - done + for p; do + case ":$PATH:" in + *:"$p":*) ;; + *) + if $APPEND; then + PATH="$PATH:$p" + else + PATH="$p:$PATH" + fi + ;; + esac + done - unset APPEND + unset APPEND } # Generalization of `path_add_to_PATH' for any variable. path_add_unsafe() { #path_add_unsafe [-a] [-d DELIM] VAR PATH... - ## Add PATH... to VAR, delimiting with DELIM (default :). - # By default, the VAR will be prepended to; passing -a will append the - # variable. -d DELIM defines the delimiter. - # - # This function has the _unsafe suffix because it uses `eval' to set - # variables. - APPEND=false; DELIM=: - while getopts ad: opt; do - case "$opt" in - a) APPEND=true ;; - d) DELIM="$OPTARG" ;; - *) return 1 ;; - esac - done - shift $(expr $OPTIND - 1) + ## Add PATH... to VAR, delimiting with DELIM (default :). + # By default, the VAR will be prepended to; passing -a will append the + # variable. -d DELIM defines the delimiter. + # + # This function has the _unsafe suffix because it uses `eval' to set + # variables. + APPEND=false + DELIM=: + while getopts ad: opt; do + case "$opt" in + a) APPEND=true ;; + d) DELIM="$OPTARG" ;; + *) return 1 ;; + esac + done + shift $(expr $OPTIND - 1) - var="$1"; shift + var="$1" + shift - for path; do - case ":$(eval "echo \$$var"):" in - *:"$path":*) ;; - *) - if $APPEND; then - eval "$var=\$$var${var:+$DELIM}$path" - else - eval "$var=$path${var:+$DELIM}\$$var" - fi - ;; - esac - done - unset -v APPEND DELIM var + for path; do + case ":$(eval "echo \$$var"):" in + *:"$path":*) ;; + *) + if $APPEND; then + eval "$var=\$$var${var:+$DELIM}$path" + else + eval "$var=$path${var:+$DELIM}\$$var" + fi + ;; + esac + done + unset -v APPEND DELIM var } -- cgit 1.4.1-21-gabe81