54 lines
1 KiB
Bash
54 lines
1 KiB
Bash
|
|
for edit in nvim vim nano vi; do
|
|
EDITOR="$(command -v ${edit})" && break
|
|
done
|
|
VISUAL="${EDITOR}"
|
|
|
|
|
|
# path-munge [OPTIONS] path
|
|
# -b add path as prefix to existing path
|
|
# -a add path as suffix to existing path (default)
|
|
function path-munge() {
|
|
local mode='suffix'
|
|
|
|
local OPTIND=1 OPTFLG=''
|
|
while getopts "ba" OPTFLG "$@"; do
|
|
case "${OPTFLG}" in
|
|
b) mode='prefix' ;;
|
|
a) mode='suffix' ;;
|
|
:) ;;
|
|
*) ;;
|
|
esac
|
|
done
|
|
shift "$((OPTIND - 1))"
|
|
|
|
if [[ :${PATH}: != *:$1:* ]]; then
|
|
case "${mode}" in
|
|
prefix) PATH="$1${PATH:+":"}${PATH}" ;;
|
|
suffix) PATH="${PATH}${PATH:+":"}$1" ;;
|
|
esac
|
|
fi
|
|
}
|
|
|
|
# shellcheck disable=SC2120
|
|
function has-superuser-priviliges() {
|
|
[[ "$(/usr/bin/groups)" == *"${1:-"wheel"}"* || "$(/usr/bin/id -u)" == "0" ]]
|
|
}
|
|
|
|
# reset bin lookup path
|
|
PATH=''
|
|
|
|
if has-superuser-priviliges; then
|
|
path-munge /usr/local/sbin
|
|
path-munge /usr/sbin
|
|
fi
|
|
|
|
path-munge /usr/local/bin
|
|
path-munge /usr/bin
|
|
|
|
# user binaries will always be first
|
|
path-munge -b ~/.local/bin
|
|
|
|
export EDITOR VISUAL PATH
|
|
|
|
unset -f has-superuser-priviliges
|