2022-02-03
This commit is contained in:
parent
f86b8496ec
commit
db393215ce
55 changed files with 1907 additions and 0 deletions
54
home/dot-local/share/bash/common.sh
Normal file
54
home/dot-local/share/bash/common.sh
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue