Saturday, September 15, 2007

Customizing Environment

Let's do a little tweaking to customize the environment (add color to the command prompt, disable beep, set up aliased commands and custom paths)
We'l do a general settings customization and then a local one.

1.First, let's make the general settings file called custom.sh in the /etc/profile.d directory.

as root:
mcedit /etc/profile.d/custom.sh


contents of this file:

#!/bin/bash

# environment customization script

# make the command prompt red for root and green for other users
if [ `id -u` = "0" ]; then
PS1="\e[0;31m\u@\h:\w\$ \e[m"
else
PS1="\e[0;32m\u@\h:\w\$ \e[m"
fi

export PS1

#disable beep
setterm -bfreq 0



now save the file and make it executable

chmod +x /etc/profile.d/custom.sh

[The only change to the command prompt is the color. You can further customize the prompt to suit your needs. This is a very nice tutorial.]

2. Now we'll make some personal customization settings for our current user.

create a file called .bash_profile in your home directory

as current user:
mcedit ~/.bash_profile

contents:

#!/bin/bash

if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi


now, create a file called .bashrc that will contain the actual customizations

mcedit ~/.basrc

contents:

#!/bin/bash
export PATH="$PATH:$HOME/bin"
now='date +"%A - %d %B %Y - %H : %M"'
alias shutdown="su -c 'poweroff;exit'"
alias restart,reboot="su -c 'shutdown -t5 -r now;exit'"


You can add any customization you like in this file.
I have a bin directory in my home directory for my personal scripts, so I added the path to that directory to the current path, so that I can call the scripts directly from the command prompt.
Also I made a small alias for the date command to display it in a custom format. For more info type man date
I also added aliases for shutting down and restarting the computer.



No comments:

Post a Comment