BASH Updates

Tue Nov 30 15:20:01 MYT 1999 (updated: Thu Jun 10 02:06:46 EST 2004 )

BASH is a GNU-based shell, that in my honest opinion is really cool. The FSF own copyright to it, and they've (the developers) made it really cool over the years (its free also!).

But mostly, we want more. With the .bashrc file placed in the user's default home directory, everything in the environment is customisable. Customisable seems to be my favourite word.

Lets start by making shortcuts.

alias ls='ls -alF --color'
alias ps='ps x'
alias vi='vim'

The above are shortcuts/aliases. They enable the ls command to list files using the -alF option, as well as provide full colour to the directory listings. This is really a very advanced directory listing. Some may prefer ls -alC --color but the best thing about bash is that its fully configurable!

Similarly, the ps x command runs a more advanced version of ps. As for the alias showing vi='vim', it simply fires up the VIiMproved version of vi. So, even application launches can be done via the .bashrc file.

The script is pretty self-explanatory and all you have to do is copy and paste it into your .bashrc file.

TERMIMON=`tty|cut -c 6-11`
COLOR1="\[\033[1;35m\]"
COLOR2="\[\033[1;34m\]"
COLOR3="\[\033[0;35m\]"
COLOR4="\[\033[0m\]"
PS1="$COLOR3[$COLOR1-$COLOR2($COLOR1\u$COLOR3@$COLOR1\h$COLOR2)$COLOR1-$COLOR2($COLOR1$TERMIMON$COLOR2)$COLOR1-$COLOR2($COLOR1\$(date +%I:%M%P)$COLOR3:$COLOR1\$(date +%d/%m/%Y)$COLOR2)$COLOR-$COLOR3-$COLOR4\n$COLOR3[$COLOR1-$COLOR2($COLOR3\w$COLOR2)$COLOR3>$COLOR4 "
PS2="$COLOR2-$COLOR1-$COLOR3-$COLOR4 "

BASH will never look the same ever again. Trust me, you'll like the new look, showing you the standard bash info, as well as the terminal (tty) you're in, the time, and the current date. And all this information gets repeated time and again, as new commands are run and the prompt is refreshed.

UPDATE: This isn't required any longer - yay, to modern terminals.Lastly, another great BASH upgrade, that will work for all consoles in an X environment. So, usage of an xterm window for example is where this will see full usage. Ever seen a VIM editor window? It shows the full directory path to where the edited file is, right? Ever wanted BASH to allow your xterm to show such information? The itch came, and the result is as follows.

prompt ()
{
MYPWD=`echo $PWD | sed "s/\/home\/byte/\~/"`
echo -ne '\033]0;loki@'$MYPWD' \007'
unset MYPWD
}
if [ "x$DISPLAY" != "x" ]; then
export PROMPT_COMMAND=prompt
fi

Essentially, what this does is display on the titlebar exactly what VIM does. Requires X to work, thats why the if statement is there. This is originally Mandrakes also... Replace 'byte' and 'loki' (the home directory and machine name respectively).


Geek Documents | bytebot.net