Replicating My OSX Terminal In Win7 with Git Bash (MinGW32) and Pik

After getting my OSX Terminal prompt all set up and loving it, I decided I wanted to have the same basic prompt in my Win7 virtual machine when I use a Git Bash (MinGW32) shell w/ MSysGit. Here’s what I came up with:

Screen shot 2010-11-25 at 10.56.27 AM.png

Note that all of the major components are available, with a few minor exceptions on the details.

 

The Pieces Of The Prompt

The title of the window shows the user @ machine name (this is a virtual machine, so the name is irrelevant to me, which is why i didn’t rename the machine)

There is a blank line after the last command and before the current location / status indicators.

The first section of the prompt, in white, is the current folder. I added a trailing / to this. Makes it easier to understand when your at the root folder or at ~/

The second section, in green, shows the current branch and status of a git repository. This is built into git, which is cool. No more parsing out git status messages. You also don’t need to source a git completion bash script. Since this is a git bash shell, that’s already done. You can use the same exports as OSX to set up your info that is shown for the git repository you’re currently in. However, there is a bug in the remote status portion of the msysgit version. it throws an error every time it tries to get the info, even though it does retrieve it. I omitted this portion from my prompt because seeing the error is annoying. But I still get to see what branch I’m on.

The third section, in red, shows the Pik ruby version that is currently being used. If you’re not using Pik on windows, and you’re using Ruby… shame on you. Pik let’s you set up and manage multiple versions of ruby on one machine, easily. It’s similar to RVM for OSX, but not as feature complete. For example, I don’t think pik has an equivalent of RVM’s “gem sets”, yet… there isn’t any built in prompt information for Pik either, so I had to create a custom function for this. A big thanks goes out to @mendicant for helping me with this.

Finally, I drop to a new line before putting “$ ” – yes, with a space – as my prompt. This keeps the prompt at the same place on the screen at all times.

 

The .bashrc Code For This

To modify your prompt in a MinGW32 shell (Git Bash Shell), create a file called “.bashrc” in the “~/” folder… that’s the user’s home folder in bash terminology, or the C:Users(your username) folder in Windows terminology. The .bashrc file is used to load up all of your settings for the shell, and run any code or command that you want to always run when the bash shell is first opened.

Inside of the .bashrc file, put the following code:


Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Derick Bailey

Derick Bailey is an entrepreneur, problem solver (and creator? :P ), software developer, screecaster, writer, blogger, speaker and technology leader in central Texas (north of Austin). He runs SignalLeaf.com - the amazingly awesome podcast audio hosting service that everyone should be using, and WatchMeCode.net where he throws down the JavaScript gauntlets to get you up to speed. He has been a professional software developer since the late 90's, and has been writing code since the late 80's. Find me on twitter: @derickbailey, @mutedsolutions, @backbonejsclass Find me on the web: SignalLeaf, WatchMeCode, Kendo UI blog, MarionetteJS, My Github profile, On Google+.
This entry was posted in Command Line, Git, Ruby. Bookmark the permalink. Follow any comments here with the RSS feed for this post.