Saturday, November 28, 2009

A guide to the ultimate Linux environment

Posted by Kallin Nagelberg

Warning: This blog will contain content that, while not necessarily offensive, will most certainly drive all but the most devout computer users to tears. Turn back now unless you meet the following conditions:

  1. You are engaged with a computer more often than you are with RL.
  2. You see and/or hear code while walking outdoors or when you try and close your eyes.
  3. You think the DRY principle should have been the eleventh commandment.
Still with me? Fantastic. We're in for some good times.

The focus here is going to be pretty specific: Customizing your Bash environment, with an emphasis on the prompt. Anyone working in a Unix based environment with any sort of frequency knows the difference between a good environment and a vanilla environment. Usually the first time you log into a Bash shell you see something like :



Bleh. Servicable, but so bland, uninformative, and quite a waste of space. I've seen better, but I want the best. In fact, every time I see a prompt these days I feel that the delta between what I'm seeing and what I'm dreaming of is really putting a dent in my productivity. In truth it's probably just the dreaming, but I'm not going to let that get in the way. That's why I've begun a quest to create the ultimate Bash prompt, and eventually an entire prompt configuration system.

Bash scripting is something I've always avoided in the past. I was a bit of a late comer to Linux, and only used it when forced to deploy new builds or perform some other sort of server maintenance. After starting a new job recently It's become apparent that this is something I can no longer avoid. I ran into one truly atrocious prompt on a Solaris box, and I said to myself right then and there: "Never again".

So, after a couple days of tinkering around with my .bashrc file I've managed to produce the following:



While far from what I'm aiming for, it's not bad. A few features of note:
  • The prompt spans two lines. One line with some important context information, and the second giving you maximum room to enter your command.
  • The first line automatically adjusts its width to fill the terminal.
  • Some color coding to make things pop.
  • Your PWD, stopped job count, current directory size, and username/hostname.
I've got lots of ideas on how to improve this prompt; from context info such as file count and cpu load, to creating a configuration system, to possibly even animating the prompt.

The code is going to live in a new GitHub repository I just created, so anyone can download it to wherever they're working and, with a couple commands, gain access to the rich feature set I look forward to creating. I hope to tag a version and create a new post detailing this preliminary version, along with installation instructions and possibly some brief tutorial-type stuff explaining how it all works.

I'm open to suggestions for features, so if there's something you'd like to see please do leave a comment! 'Till next time...

0 comments:

Post a Comment