nnn/plugins/suedit

22 lines
418 B
Plaintext
Raw Normal View History

2019-10-14 01:06:11 +00:00
#!/usr/bin/env sh
# Description: Edit file as superuser
#
# Shell: POSIX compliant
# Author: Anna Arad
EDITOR="${VISUAL:-${EDITOR:-vi}}"
2019-10-14 01:06:11 +00:00
is_cmd_exists () {
which "$1" > /dev/null 2>&1
echo $?
}
2020-01-15 11:48:10 +00:00
if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
2019-10-14 01:06:11 +00:00
sudo "$EDITOR" "$1"
2020-01-15 11:48:10 +00:00
elif [ "$(is_cmd_exists sudoedit)" -eq "0" ]; then
sudoedit "$1"
2019-10-14 01:06:11 +00:00
elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
doas "$EDITOR" "$1"
fi