Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit cd34335

Browse files
author
excalibur1234
committed
improve use of /usr/bin/nano and envirnment variables
1 parent 13b930f commit cd34335

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

pacui

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,54 +1446,48 @@ function func_c
14461446
if [[ -n "$file" ]] && (( check == 1 )) # here $check variable needs to be 1 in order to continue normally and display files in a text editor.
14471447
then
14481448

1449-
set +u # temporarily disable strict mode for environment variables. "$EDITOR" variable gets used extensibely in the following code!
1449+
set +u # temporarily disable strict mode for environment variables. "$EDITOR" and "$SUDO_EDITOR" variable gets used extensibely in the following code!
14501450

1451-
if [[ "$( echo "$file" | cut -c -6 )" == "/home/" ]]
1452-
# if "file"'s first characters are "/home/", the "file" should NOT be opened as root!
1451+
if [[ "$( echo "$file" | cut -c -6 )" == "/home/" ]] # check, if "file"'s first characters is "/home/"
14531452
then
1454-
# if $EDITOR variable does not exist, set it to 'nano'
1455-
[[ -z "$EDITOR" ]] && EDITOR='nano'
1456-
# open "file" in "EDITOR": (attention: "$file" (including " symbols) does NOT WORK!!!, but strangely $file (without " symbols") works fine.)
1457-
$EDITOR "$file"
1453+
# if $file starts with "/home/", open it in "EDITOR" (without root privileges).
1454+
# "${EDITOR:-/usr/bin/nano}" outputs the content of the $EDITOR environment variable. if it is not set, '/usr/bin/nano' gets used.
1455+
"${EDITOR:-/usr/bin/nano}" "$file"
1456+
14581457
elif [[ "$file" == "/etc/sudoers" ]]
14591458
then
14601459
# the sudoers file should never be edited directly! if something goes wrong, sudo stops working. instead, visudo should be used. this is much safer.
1461-
sudo EDITOR=nano visudo
1460+
# if $SUDO_EDITOR variable does not exist, use 'nano'. visudo uses $SUDO_EDITOR variable by default!
1461+
sudo EDITOR="${SUDO_EDITOR:-/usr/bin/nano}" visudo
1462+
14621463
elif [[ "$file" == "/etc/pacman.d/mirrorlist" ]] || [[ "$file" == "/etc/pacman.conf" ]]
14631464
then
1464-
# if $EDITOR variable does not exist, set it to 'nano'
1465-
[[ -z "$EDITOR" ]] && EDITOR='nano'
1466-
# open "file" in "EDITOR": (attention: "$file" (including " symbols) does NOT WORK!!!)
1467-
sudo $EDITOR "$file"
1465+
sudo "${EDITOR:-/usr/bin/nano}" "$file"
14681466
sudo pacman "$argument_flag"-Syyu # apply changes
1467+
14691468
elif [[ "$file" == "/etc/pacman-mirrors.conf" ]]
14701469
then
1471-
# if $EDITOR variable does not exist, set it to 'nano'
1472-
[[ -z "$EDITOR" ]] && EDITOR='nano'
1473-
# open "file" in "EDITOR": (attention: "$file" (including " symbols) does NOT WORK!!!)
1474-
sudo $EDITOR "$file"
1470+
sudo "${EDITOR:-/usr/bin/nano}" "$file"
14751471
sudo pacman-mirrors -f 0 && sudo pacman "$argument_flag"-Syyu
1472+
14761473
elif [[ "$file" == "/etc/fstab" ]] || [[ "$file" == "/etc/crypttab" ]]
14771474
then
1478-
# if $EDITOR variable does not exist, set it to 'nano'
1479-
[[ -z "$EDITOR" ]] && EDITOR='nano'
1480-
# open "file" in "EDITOR": (attention: "$file" (including " symbols) does NOT WORK!!!)
1481-
sudo $EDITOR "$file"
1475+
sudo "${EDITOR:-/usr/bin/nano}" "$file"
14821476
sudo mount -a # mount all drives/partitions in /etc/fstab file. this shows immediately mistakes in your /etc/fstab file and prevents non-working systems.
1477+
14831478
elif [[ "$file" == "/etc/mkinitcpio.conf" ]]
14841479
then
1485-
[[ -z "$EDITOR" ]] && EDITOR='nano'
1486-
sudo $EDITOR "$file"
1480+
sudo "${EDITOR:-/usr/bin/nano}" "$file"
14871481
sudo mkinitcpio -P && sudo grub-mkconfig -o /boot/grub/grub.cfg # apply changes # "grub-mkconfig -o /boot/grub/grub.cfg" == "udpate-grub" (in manjaro)
1482+
14881483
elif [[ "$file" == "/etc/default/grub" ]] || [[ "$file" == "/boot/grub/custom.cfg" ]]
14891484
then
1490-
[[ -z "$EDITOR" ]] && EDITOR='nano'
1491-
sudo $EDITOR "$file"
1485+
sudo "${EDITOR:-/usr/bin/nano}" "$file"
14921486
sudo grub-mkconfig -o /boot/grub/grub.cfg # apply changes # "grub-mkconfig -o /boot/grub/grub.cfg" == "udpate-grub" (in manjaro)
1487+
14931488
else
14941489
# start "sudo nano $file" for all other files (not mentioned separately in elif-statements above)
1495-
[[ -z "$EDITOR" ]] && EDITOR='nano'
1496-
sudo $EDITOR "$file"
1490+
sudo "${EDITOR:-/usr/bin/nano}" "$file"
14971491
fi
14981492

14991493
set -u

0 commit comments

Comments
 (0)