Results 1 to 10 of 10

Thread: HOWTO: Easily edit you configuration files

  1. #1
    Join Date
    Sep 2005
    Location
    Rio de Janeiro, Brasil
    Beans
    6
    Distro
    Ubuntu Breezy 5.10

    Lightbulb HOWTO: Easily edit you configuration files

    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.
    Last edited by zipmegabyte; October 20th, 2005 at 12:17 AM. Reason: Missing variable declaration in easyedit.sh!

  2. #2
    Join Date
    Sep 2005
    Location
    MD
    Beans
    19

    Re: HOWTO: Easily edit you configuration files

    Great little howto.. Never thought to do that. Just read this on my lunch break, and already have several setup. Thanks!

  3. #3
    Join Date
    Sep 2005
    Location
    Rio de Janeiro, Brasil
    Beans
    6
    Distro
    Ubuntu Breezy 5.10

    Re: HOWTO: Easily edit you configuration files

    I just found a bug that prevented it from running from a .desktop file or the run dialog (ALT+F2) and updated the howto. You'll have to redo Step 1, cause I changed the /usr/bin/easyedit.sh file.

  4. #4
    Join Date
    Sep 2005
    Beans
    89
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: HOWTO: Easily edit you configuration files

    Nice idea.

    If you got time to make further improvements, a list with all the config with a little discription for each of them would be great. You could write f.eks configoverview, and a text file with the overview would pop up.

    Turgon

  5. #5
    Join Date
    Sep 2005
    Location
    Rio de Janeiro, Brasil
    Beans
    6
    Distro
    Ubuntu Breezy 5.10

    Re: HOWTO: Easily edit you configuration files

    Can you explain wat you mean? What is f.eks configoverview? I googled it but found nothing in a language I could undestand.

    Btw I updated the script again. Seems like I forgot to declare a variable in the first script. At least now I tested the steps and it's ok.

  6. #6
    Join Date
    Jul 2005
    Beans
    431

    Re: HOWTO: Easily edit your configuration files

    That's really neat!

    I like typing vi /etc/fstab LOL-- but that's just me

    This is a good idea, and should be considered to be included in Dapper Drake by default

  7. #7
    Join Date
    Jul 2005
    Beans
    89
    Distro
    Kubuntu 6.06

    Re: HOWTO: Easily edit your configuration files

    Very nice...I'm using it now for my fstab and xorg configs...thanks for the tip!
    Kubuntu 6.06

  8. #8
    Join Date
    Apr 2005
    Location
    Under the Jolly Roger
    Beans
    571

    Re: HOWTO: Easily edit you configuration files

    Nice work. It's not something I'd use myself, as I prefer to do all config tasks manually in order to focus on the task at hand, but I can this being useful to newbies.
    My sole duty is to my own happiness and well-being. I recognize no other.

  9. #9
    Join Date
    Oct 2004
    Location
    Moscow, Russia
    Beans
    9
    Distro
    Ubuntu Breezy 5.10

    Re: HOWTO: Easily edit your configuration files

    Ok, save the file, return to terminal and type:

    Code:
    sudo chmod 777 /usr/bin/easyedit.sh
    It would be better to use 755 as permissions instead of 777. To have world-writable files (especially executables) on system is a serious security risk.

  10. #10
    Join Date
    Sep 2005
    Location
    Rio de Janeiro, Brasil
    Beans
    6
    Distro
    Ubuntu Breezy 5.10

    Re: HOWTO: Easily edit your configuration files

    You're probably right. As I don't care much about security in this machine I tend to be a little too permissive.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •