3 # Useful bash functions. This is sourced by the environment file.
4 # These are available to scripts, but you shouldn't use them in scripts if you
5 # want them to be portable.
8 # Usage: pathremove /path/to/bin [PATH]
9 # Eg, to remove ~/bin from $PATH
10 # pathremove ~/bin PATH
15 local PATHVARIABLE=${2:-PATH}
16 for DIR in ${!PATHVARIABLE} ; do
17 if [ "${DIR}" != "${1}" ] ; then
18 NEWPATH="${NEWPATH:+${NEWPATH}:}${DIR}"
21 export ${PATHVARIABLE}="${NEWPATH}"
24 # Usage: pathprepend /path/to/bin [PATH]
25 # Eg, to prepend ~/bin to $PATH
26 # pathprepend ~/bin PATH
27 function pathprepend {
28 pathremove "${1}" "${2}"
29 [ -d "${1}" ] || return
30 local PATHVARIABLE="${2:-PATH}"
31 export ${PATHVARIABLE}="${1}${!PATHVARIABLE:+:${!PATHVARIABLE}}"
34 # Usage: pathappend /path/to/bin [PATH]
35 # Eg, to append ~/bin to $PATH
36 # pathappend ~/bin PATH
38 pathremove "${1}" "${2}"
39 [ -d "${1}" ] || return
40 local PATHVARIABLE=${2:-PATH}
41 export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}${1}"
44 # Usage: ssource /path/to/shellscript
45 # Checks if the file exists before sourcing it
47 [ -r "${1}" ] && source "${1}"
50 # Sets colours to be appropriate for a light on dark terminal
53 source "${HOME}/.bash/colors"
56 # Sets the colours to be appropriate for a dark on light terminal
59 source "${HOME}/.bash/colors"
63 # Creates the directory if it doesn't exist, and changes into it
70 # Load local functions
71 ssource "${HOME}/.bash/functions_local"