]> code.delx.au - dotfiles/blobdiff - .bash/functions
bash: reorder initialisation
[dotfiles] / .bash / functions
index a3bb6c49d48a6978f0fcffb61a2d6838aa316329..7420d281e05d62c596046dd619ba3ca036322b50 100644 (file)
@@ -9,66 +9,60 @@
 # Eg, to remove ~/bin from $PATH
 #     pathremove ~/bin PATH
 function pathremove {
-       local IFS=':'
-       local NEWPATH
-       local DIR
-       local PATHVARIABLE=${2:-PATH}
-       for DIR in ${!PATHVARIABLE} ; do
-               if [ "${DIR}" != "${1}" ] ; then
-                       NEWPATH="${NEWPATH:+${NEWPATH}:}${DIR}"
-               fi
-       done
-       export ${PATHVARIABLE}="${NEWPATH}"
+    local IFS=':'
+    local NEWPATH
+    local DIR
+    local PATHVARIABLE=${2:-PATH}
+    for DIR in ${!PATHVARIABLE} ; do
+        if [ "${DIR}" != "${1}" ] ; then
+            NEWPATH="${NEWPATH:+${NEWPATH}:}${DIR}"
+        fi
+    done
+    export ${PATHVARIABLE}="${NEWPATH}"
 }
 
 # Usage: pathprepend /path/to/bin [PATH]
 # Eg, to prepend ~/bin to $PATH
 #     pathprepend ~/bin PATH
 function pathprepend {
-       pathremove "${1}" "${2}"
-       [ -d "${1}" ] || return
-       local PATHVARIABLE="${2:-PATH}"
-       export ${PATHVARIABLE}="${1}${!PATHVARIABLE:+:${!PATHVARIABLE}}"
+    pathremove "${1}" "${2}"
+    [ -d "${1}" ] || return
+    local PATHVARIABLE="${2:-PATH}"
+    export ${PATHVARIABLE}="${1}${!PATHVARIABLE:+:${!PATHVARIABLE}}"
 }
 
 # Usage: pathappend /path/to/bin [PATH]
 # Eg, to append ~/bin to $PATH
 #     pathappend ~/bin PATH
 function pathappend {
-       pathremove "${1}" "${2}"
-       [ -d "${1}" ] || return
-       local PATHVARIABLE=${2:-PATH}
-       export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}${1}"
-}
-
-# Usage: ssource /path/to/shellscript
-# Checks if the file exists before sourcing it
-function ssource {
-       [ -r "${1}" ] && source "${1}"
+    pathremove "${1}" "${2}"
+    [ -d "${1}" ] || return
+    local PATHVARIABLE=${2:-PATH}
+    export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}${1}"
 }
 
 # Usage: is_function something
 # Check if a function exists
 function is_function {
-       declare -Ff "$1" > /dev/null
+    declare -Ff "$1" > /dev/null
 }
 
 # Usage: find_up_recurse somefile
 # Check if a file named somefile exists in this directory or any parent
 function find_up_recurse {
-       d="$1"
-       pushd . > /dev/null
-       while [ "$PWD" != "/" ]; do
-               if [ -e "$d" ]; then
-                       popd > /dev/null
-                       return 0
-               fi
-               cd ..
-       done
-       popd > /dev/null
-       return 1
+    d="$1"
+    pushd . > /dev/null
+    while [ "$PWD" != "/" ]; do
+        if [ -e "$d" ]; then
+            popd > /dev/null
+            return 0
+        fi
+        cd ..
+    done
+    popd > /dev/null
+    return 1
 }
 
 # Load local functions
-ssource "${HOME}/.bash/functions_local"
+[ -r "${HOME}/.bash/functions_local" ] && source "${HOME}/.bash/functions_local"