aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/suedit
blob: 7ba00db1b47cca3f74bad36251735b3cacf4defe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env sh

# Description: Edit file as superuser
#
# Shell: POSIX compliant
# Author: Anna Arad

EDITOR="${EDITOR:-vim}"

is_cmd_exists () {
    which "$1" > /dev/null 2>&1
    echo $?
}

if [ "$(is_cmd_exists sudoedit)" -eq "0" ]; then
    sudoedit "$1"
elif [ "$(is_cmd_exists sudo)" -eq "0" ]; then
    sudo "$EDITOR" "$1"
elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
    doas "$EDITOR" "$1"
fi