As I mentioned a couple of post ago, I started a new job in which I am doing more heavy development, and I am loving it. Now I am a very paranoid programmer and I am this way because I’ve destroyed hours of work with some poorly coded lines. As a result I typically backup the files I am working on before I edit them and this has saved me a few times. Couple this with the fact I am working in unfamiliar code of the new job and I find myself doing a quick ‘cp’ before every ‘vi’.
Something else about me, I am very lazy and I like to automate as much of my life as possible. With this, I created a nice little BASH function to handle this task for me.
It’s pretty basic and I add this to my .bash_profile. Now when I type ‘evim filename’, this little function will make a copy of the file in a Backup folder I defined before launching it with Vim. It will also add a time stamp as part of the backed up filename.
So I've been asked a couple of times for this post and I keep not getting around to it so thought I would take some time and get this out. My bash prompt is very informative, long, and functional and that is they way I like it. One prompt actually results in 2 lines in my terminal being used. This is my current Bash Prompt in terminal:
- First thing to notice is my command prompt is actually on the second line, below all the information. This is by design.
- The first part of the prompt in the typical username and computer name. Nothing special. A lot of people remove this but I keep it. When all the voices in my head start shouting at each other I can always look at my command prompt and remember who I am.
- Next is my location on the computer. Again, a lot of people will just have this piece represent only the current folder but I like to see the entire path. Main reason is I might have several Project folders on my system and this helps me to see which Project folder I am in.
- Then comes this little piece of magic that I love, my Git Branch. This section only displays when I am in a directory structure related to a Git checkout and shows me which branch of that git checkout I am working on. This section, depending on your system, may require different set ups. Since I am on my OSX system what I am using is
git-prompt.sh). One of the better post on how to install this correctly can be found on a StackOverFlow.com thread. Keep in mind, if I am not on a Git branch none of this section displays, not even the - which makes it is very clean.
- Finally I like to add a time stamp to the end of my prompt. This allows me to return to a console and figure out when I last ran something from that window. It's very helpful. The time doesn't stay current, meaning it won't continue to keep time, it will only show you the time when that prompt was created and that is it.
The prompt does include the different colors for the different sections if your system supports it and most Unix type console do support it. Here is the magic that makes this happen.
There are a couple of ways to play around with this, tweak it until you find what you like, without impacting your system permanently until you want to. At the command prompt simply copy and past the entire line including the word "export", you should be able to see the new prompt immediately. Once you've tweaked it to exactly what you want you can add it to either you
.bash_profile files however you can remove the word export when you do that and just start the line at PS1
If you would like a version without the Git Branch indicator this version should work for you
Here is a link to some other helpful and fun Bash Prompts
Enjoy and Happy Bash'ing
Update: My buddy @johncongdon on twitter pointed out by adding
export GIT_PS1_SHOWDIRTYSTATE=1 to your
.bash_profile then you will also get the status of the Git branch.