KishCom

Developer. Gamer. Yo-Yo Thrower.

Pimp Your Shell Out

These days if I'm not in a web browser I'm in a shell or terminal window. Working in a terminal window (henceforth shell) can be daunting, but there's a myriad of things you can do to customize, and friendly up your shell.

This primer assumes you're using Ubuntu, or some other Debian variant, however since all our changes are mostly to do with Bash itself you should be able to follow this guide on any OS packing a Bash shell as its default terminal (replacing aptitude with your OSes package manger of course -- I'm sure you can do this on OSX, but I'm not going to bother looking up how - you'll probably need MacPorts or something similar to make things smooth).

Getting what you need
Understandably, Ubuntu does not package shell toys and sillyness as part of the default install.
sudo aptitude install git-core figlet toilet fortune cowsay
Enter your password when prompted and install the packages required.
Next we're going to grab the LS_COLORS from trapd00rs github page. LS_COLORS does exactly what the name says it does: makes your ls output colours -- heh -- more colours than default I mean. Take a look at the Github repo for an example. This command gets the latest version of LS_COLORS and places it in a hidden directory in your home folder called .LS_COLORS:
cd ~
git clone https://github.com/trapd00r/LS_COLORS.git .LS_COLORS 

Now to make pretty ASCII-art like headers, we're going to use the figlet and toilet tools, but since we're going all out in our pimping we want more fonts than Ubuntu provides. Grab the latest version of figlet fonts and unzip them to your figlet folder like this:
wget http://www.jave.de/figlet/figletfonts40.zip
sudo unzip figletfonts40.zip -d /usr/share/figlet/
sudo mv /usr/share/figlet/fonts/* /usr/share/figlet/.

If you're still with me this far, you can test out your handy work by testing figlet out:
figlet -f trek "Star Trek"

Pretty slick eh?

Pretty Colours
Open your .bashrc file - for some reason Ubuntu likes to keep the more useful aliases commented out - I use "ll" (that's two lower case "L"s) to display a ls -lah --color, as well as a few others.
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    #test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    eval $( dircolors -b $HOME/.LS_COLORS/LS_COLORS )
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto' #for old DOS dogs
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

### Enable ls aliases #Optional
alias ll='ls -lah --color'
alias la='ls -A'
alias l='ls -CF'

The important part here is commenting out the line starting with "test -r" and adding in the "eval $( dircolors" line. This makes the LS_COLORS we downloaded earlier active on login. Logout of your shell and log back in, type 'ls' and enjoy the pretty colour coded file types.

Adding in some Zen
You may have seen cowsay and fortune used together before, goes something like this:
cowsay `fortune`

You now have a cow quoting you fortunes, but again, we're going all out in our shell pimping, we want custom cows and custom fortunes. You can see all the cows your system has and test them with the "-f" flag of cowsay:
ls /usr/share/cowsay/cows
#snip - use any file name you see listed without the .cow extension like this:
cowsay -f ghostbusters "Who you gunna call?"


Your Favourite Quotes
In keeping with our super-custom motif, we're going to generate our own list of fortunes to use. You probably have some favourite quotes of your own. Open your favourite text editor and start collecting them in a new text file separating each quote out with "%" (also make sure your text file starts with "%"), so you'll have a file that looks kinda like this:
%
We cannot enter into alliances until we are acquainted with the designs of our neighbors.
%
The quieter you become the more are able to hear.
%
The clever combatant imposes his will on the enemy, but does not allow the enemy's will to be imposed on him.
%
Opportunities multiply as they are seized.
Save that file as "my_fortunes" in your home folder, open a new shell and run:
strfile ~/my_fortunes

If all goes well, you'll see an output telling you the name of the .dat file created, how many strings there were and the longest/shortest strings. Now we just need to copy that to our fortunes folder and we'll be all set. Do that by simply:
sudo mv ~/my_fortunes* /usr/share/games/fortunes/.

Now lets tie it all together and enjoy the fruits of our labour:
cowsay -f hellokitty `fortunes my_fortunes`

Finally, here's were we unleash your inner creative monster and use all the tools we've gathered here to build a cool intro for your shell. Append this hot mess (or something similar) to the end of your .bashrc file:
figlet -f banner3-D -w 160 "Something" #Get creative here! the -w flag is your console width, adjust as needed
#cat /etc/hostname | figlet -f banner3-D -w 160 #Print the hostname
echo "" # Just a spacer
cowsay -f hellokitty `fortunes my_fortunes`
echo ""

Keep in mind you can see all your "cows" by 'ls /usr/share/cowsay/cows' and all of your installed figlet fonts by 'ls /usr/share/figlet/'. That's all there is to it. Now go forth and make your shell your own.

See errors? Want to make a contribution? Tweet at me.

Back to KishCom.com
KishCom.Com

Table of Contents