I use to mess around with configuration files all the time and just got sick of having to type "sudo gedit /etc/fstab" or "sudo gedit /etc/X11/xorg.conf" over and over or search for them in the terminal cache.
So I came up with a solution that might be useful for some of you.
I just created some shell scripts in my /usr/bin with the same names of the configuration files I edit the most, so whenever I type "fstab" it will open /etc/fstab for edition with root privileges, using gedit if I'm in Gnome or nano if I'm in pure terminal. All automated and hassle-free.
STEP 1:
So first we need the main script, that I'll call "easyedit.sh". Open a terminal window and type:
Code:
sudo gedit /usr/bin/easyedit.sh
Paste the following text into gedit:
Code:
#!/bin/sh
TERM_EDITOR="nano"
X_EDITOR="gedit"
X_SUDO="gnome-sudo"
FILE=$1
TERMINAL="`tty`"
if [ $? -eq 1 ];
then
TERMINAL="none"
fi
case $TERMINAL in
/dev/tty[1-8])
if [ `whoami` = "root" ];
then
$TERM_EDITOR $FILE
else
sudo $TERM_EDITOR $FILE
fi
;;
/dev/pts/*|/dev/ttyp*|none)
if [ `whoami` = "root" ];
then
$X_EDITOR $FILE&
else
$X_SUDO "$X_EDITOR $FILE"&
fi
;;
*)
esac
Ok, save the file, return to terminal and type:
Code:
sudo chmod 777 /usr/bin/easyedit.sh
STEP2:
Now all we need are the files that will have the same name as the ones you edit the most. Here is how to do fstab:
Code:
sudo gedit /usr/bin/fstab
then paste this into gedit:
Code:
#!/bin/sh
FILE="/etc/fstab"
easyedit.sh $FILE
Save file and make it executable using 'sudo chmod 777 /usr/bin/fstab'.
That's it. Repeat STEP 2 for any configuration file you want, just remember to save them into /usr/bin with the same name as the original files (for easy remembering) and to change the value of FILE to match the path to the original file. I also created scripts for /boot/grub/menu.lst, /etc/X11/xorg.conf and /etc/apt/sources.list.
Remeber: you can use this command wherever you want, be it in gnome, KDE or pure terminal. You can also change TERM_EDITOR, X_EDITOR and X_SUDO in easyedit.sh to match your tastes.
Bookmarks