2022-02-03

This commit is contained in:
Louis Seubert 2022-02-03 19:33:04 +01:00
commit db393215ce
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
55 changed files with 1907 additions and 0 deletions

View file

@ -0,0 +1,54 @@
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