Minimalist Linux 01: Customizing Your Bash Prompt
I've been meaning to do this for a while -- a themed set of blog entries about a common topic following in the veins of Simon's CSS stuff or Mark's Python stuff. And the topic that feels right to me is "Minimalist Linux". I won't claim that these are any big deal at all but just the little things that make stuff easier. And even if no one else learns anything from it, I'll have documented what I do and what I like which is helpful to me*. And so ... Let's talk about Bash.
Note: I'm writing this series purely from a minimalist perspective. I'll talk about the very, very small subset of Linux that I personally use. I know there is so much more for everything I'm talking about. I'm choosing to NOT talk about it. And I'm simplifying a lot. Bear that in mind -- a lot. Readers are encouraged to correct me, give comments, etc.
Bash or "Bourne Again Shell" is the basic command shell you see when you login to or ssh into a Linux box. It looks basically like a blank screen where you type commands to be executed. The prompt generally shows you the username and maybe the directory. Now Feedster has just graduated to a 3rd box at Rackspace and just knowing what box I'm in at any time is actually difficult. I mean a command shell is a command shell is a command shell. Now I could solve this locally on my personal box but I use lots of boxes -- a Windows desktop, a Linux desktop and 1 of 2 laptops for when I want to code in the living room on the couch (yeah --- its a happening time around here, let me tell you). So clearly a server side approach is needed. And all I really need is to customize the shell as follows: [ servername - username - current directory ] $ (this is where the commands would go)
Now the per user configuration for Bash is commonly stored in /home/username/.bash
So what I did was edited this file (which had nothing in it meaning that the system defaults were used) and add this: PS1='[H - u - w/ ]n$'
PS1 is the internal Bash variable for the prompt. H is the full hostname for the machine, u is the username and w is the working directory. Now I also added a / at the end of it intentionally even though this wouldn't normally be there. Why? Well I'm a VI junkie and with character mode VI everything is copyable. And since you do so much move to this directory, No! that directory, No over here!, I find that being able to copy it and paste it is really helpful.
After editing this file I had to tell Bash to reload its profile so I typed source /home/username/.bash
And that reloaded it giving me my new prompt. And I was happy.
References
A quick Google turned up these:
Footnotes
*You do realize that a huge amount of blogging is about clarifying your own knowledge and setting things down for yourself, don't you? And with Feedster's ability to search only your own blog, this is very, very useful.
When:
3:35:25 PM |
Permalink: |
|
IM Me About This
|