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:</p>

My OSX Terminal Prompt (Reposted from Tumblr)