Customized bash command prompt with line separator and other goodies

I wanted to have a fancy looking and very useful terminal windows with customize command prompt so after digging I build something as below for me:

Image

So what it have:

  • Line Separator including current time at the end of the terminal
  • History counter along with current command counter
  • Logged user @ Hostname
  • Current working folder $

Here is what I have done. First created a file call .avkashbash_profile at my $HOME folder as below:

fill=”-“
reset_style='[33[00m]’
status_style=$reset_style'[33[0;32m]’ # gray color; use 0;37m for lighter color
prompt_style=$reset_style
command_style=$reset_style'[33[0;32m]’ # bold black
# Prompt variable:
PS1=”$status_style”‘$fill[T]n'”$prompt_style”‘${debian_chroot:+($debian_chroot)}e[0;31me[47m[!:#]e[
0m-e[1;33m[u@h]e[0mn[w]e[0;32m$ ‘”$command_style “
# Reset color for command output
# (this one is invoked every time before a command is executed):
function prompt_command {
# create a $fill of all screen width minus the time string and a space:
let fillsize=${COLUMNS}-11
fill=””
while [ “$fillsize” -gt “0” ]
do
fill=”-${fill}” # fill with underscores to work on
let fillsize=${fillsize}-1
done
}
PROMPT_COMMAND=prompt_command

To make the setting permanent, just add the following code in .bash_profile first:

if [ -f “$HOME/.avkashbash_ps1” ]; then
. “$HOME/.avkashbash_ps1”
fi

And then run the following command to set it:

$sources .bash_profile

Or if you don’t want to make it permanent, just add the following code to .bashrc first:

if [ -f “$HOME/.avkashbash_ps1” ]; then
. “$HOME/.avkashbash_ps1”
fi

And then run the following command to set it:

$sources .bashrc

Thats all.

Thanks for the guys at here and here!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s