Add Time and Separator Line on Terminal (Ubuntu)

It would be nice if I can add separator line and time between commands in Terminal on Ubuntu (Linux).

So, I began to search to achive this.
While after I found a way.

Here are the steps.

  • Create a new text file named ".bash_separator" in home folder. Then open it with a text edior and  add the below text and save it.

# Fill with minuses
# (this is recalculated every time the prompt is shown in function prompt_command):
fill="--- "

reset_style='\[\033[00m\]'
status_style=$reset_style'\[\033[0;90m\]' # gray color; use 0;37m for lighter color
prompt_style=$reset_style
command_style=$reset_style'\[\033[1;29m\]' # bold black
# Prompt variable:
PS1="$status_style"'$fill \t\n'"$prompt_style"'${debian_chroot:+($debian_chroot)}\u@\h:\w\$'"$command_style "

# Reset color for command output
# (this one is invoked every time before a command is executed):
trap 'echo -ne "\e[0m"' DEBUG

function prompt_command {
# create a $fill of all screen width minus the time string and a space:
let fillsize=${COLUMNS}-9
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="-${fill}" # fill with underscores to work on
let fillsize=${fillsize}-1
done

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
bname=`basename "${PWD/$HOME/~}"`
echo -ne "\033]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
;;
*)
;;
esac

}

PROMPT_COMMAND=prompt_command

  • And now open .bashrc file with text editor. This file is hidden and located in the home folder. Then, append the below text to the end of the file and save it.

#time and separator line configuration file
if [ -f "$HOME/.bash_separator" ]; then
. "$HOME/.bash_separator"
fi

  • Restart the teminal or call the below command:

$ source ~/.bashrc

That's it. Now, your terminal should look like this: 
Terminal with Time and Separator Line

 

Reference / Thanks:

Share Share Editor: editor | Posted: 2012/12/15 | Views: 10672

Comments

4 + 9 =
Name 06/20/2013 13:34:39
Superb! Thank you!
Home | Search | Contact | Terms
Editor
radyo dinle aşı takvimi podcast multimedia blog bedava dinle izle kongreler online müzik dinle selected videos nasheed music videos