3/16/2017

Bash Customization - Colorizing Prompt

Spending extended periods of time with any tool usually makes me want to tweak it to fit my particular quirky desires, and the Linux terminal is no exception.  Having cut my teeth on "normal" distributions, I had grown accustomed to the bland and colorless user@hostname shell session and was perfectly happy, mainly because I didn't know what I was missing.  Until, that is, I stumbled upon one of Linux Mint's early releases that included a colorized bash prompt and a funny little quote (courtesy of fortunes.)

I spent countless hours searching forums for "terminal customization" tips, and pasted more than a few random settings into config files without knowing the impact.  And we won't mention the time I destroyed my system badly enough to require a rebuild.

And then I found the Bash RC Generator site (http://bashrcgenerator.com) which provides a WYSIWYG editor for building custom terminal prompts.  Simply drag the available elements into the "your selection" sandbox and a preview of the changes - double clicking on an element in the sandbox allows you to set foreground and background color values!  Once you have found a customization you like, simple copy the code and add it to your .bashrc file - the site even includes how-to steps for updating your config files and the references for bash customization.

By adding the code snippet below, the terminal prompt on my Ubuntu Zesty testbox went from this:
...to this:

Custom PS1 code added to .bashrc config file
export PS1="[\[$(tput sgr0)\]\[\033[38;5;10m\]\d\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]\[\033[38;5;10m\]-\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]\[\033[38;5;10m\]\t\[$(tput sgr0)\]\[\033[38;5;15m\]] \[$(tput sgr0)\]\[\033[38;5;14m\]\u@\H\[$(tput sgr0)\]\[\033[38;5;11m\]:\W\[$(tput sgr0)\]\[\033[38;5;15m\] \\$\[$(tput sgr0)\]"
Note, most of that code is used for the colorization of the variables. If you'd prefer the same text uncolored, the code block would be this:
export PS1="[\d - \T] \u@\H:\W \\$\[$(tput sgr0)\]"

MacOS Tweaking 101

Is your beloved hunk of Cupertino silicon underperforming?  Wish your Mac had a little more zip?  Then you'll love these tips on squeez...