Customize your Linux Terminal (Bash)

Linux14080

So the terminal is something that a program uses all the time but the default terminals on Unix distros looks very plain and boring in my opinion.

While I really like the Kali Linux terminal style I use my Xubuntu distro much more often, its my personal favourite. So I decided to customize it and make it look more interesting.

Before

Original Terminal Xubuntu

After

Mo Customized Linux Terminal

The customized terminal when opened prints:

How to get the above terminal style

To replicate the colours and style, simply copy the preferences from the image below. These settings should be pretty similar on all graphics based Linux distributions.

Xubuntu Terminal Style Preferences

You can download the Aperture Laboratories background image here: aperture-laboratories-terminal-background.png

You will have to modify your bash preference files to get the terminal welcome message printed at the top of the terminal when you spawn a new shell (bash prompt).

Navigate to your home directory and add the following to the end of your .bash_profile file:

# Terminal welcome message
terminal_welcome() {
  date +"%A, %d %B %Y, %I:%M:%S %p" #Date in nice format

  # CPU
  echo -n CPU usage: $(echo print `top -n 1 | tr -s " " | cut -d$" " -f10 | tail -n +8 | head -n -1 | paste -sd+ | bc`/ `nproc` | python)%
  echo -n " | "

  # Memory in use
  echo -n Available memory: `cat /proc/meminfo | grep "MemFree" | tr -s " " | cut -d$" " -f2-` / `cat /proc/meminfo | grep "MemTotal" | tr -s " " | cut -d$" " -f2-`
  echo -n " | "
    
  # XX% of storage used (XXG out of XXG)
  echo `df -h --total | tail -1 | tr -s " " | cut -d$' ' -f5` storage used \(`df -h --total | tail -1 | tr -s " " | cut -d$' ' -f3` / `df -h --total | tail -1 | tr -s " " | cut -d$' ' -f2`\)

  fortune | cowsay
  echo -e "\n"
}

Next, append the following to .bashrc file:

# Source my bash profile in interactive mode
source ~/.bash_profile

# Show terminal welcome message
terminal_welcome

Now restart your terminal or spawn a new shell to see the results!

Note:  The function which determines the CPU usage is a little slow so you may notice a slight delay (~150ms) every time you spawn a new shell. If this is a massive problem for you, simply remove the CPU usage line from the terminal welcome message.


Leave a comment

(required)(will not be published)(required)

Comments

There are no comments yet. Be the first to add one!