diff options
| author | 2019-10-14 04:06:11 +0300 | |
|---|---|---|
| committer | 2019-10-14 06:36:11 +0530 | |
| commit | 49bee694909a706aff4f04200e24facadf5ff55b (patch) | |
| tree | 5b6a62f96f86523cac3e03d35a7b796d4377bcba | |
| parent | ab0fe6c408656718a3a27380648552828c2d0143 (diff) | |
| download | nnn-49bee694909a706aff4f04200e24facadf5ff55b.tar.gz | |
suedit plugin (#359)
| -rw-r--r-- | plugins/README.md | 1 | ||||
| -rwxr-xr-x | plugins/suedit | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/plugins/README.md b/plugins/README.md index 3a40ae4..85550ca 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -38,6 +38,7 @@ The currently available plugins are listed below. | readit | sh | pdftotext, mpv,<br>pico2wave | Read a PDF or text file aloud | | ringtone | sh | date, ffmpeg | Create a variable bitrate mp3 ringtone from file | | splitjoin | sh | split, cat | Split file or join selection | +| suedit | sh | sudoedit/sudo/doas | Edit file using superuser permissions | | sxiv | sh | sxiv | View images in dir, set wallpaper, copy path ([config](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts))| | thumb | sh | [lsix](https://github.com/hackerb9/lsix) | View thumbnail of an image or dir of images | | transfer | sh | curl | Upload file to transfer.sh | diff --git a/plugins/suedit b/plugins/suedit new file mode 100755 index 0000000..7ba00db --- /dev/null +++ b/plugins/suedit @@ -0,0 +1,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 |