Archive for the ‘Development’ Category

Unix prompt (PS1) with git branch name

Monday, July 14th, 2008

Working with Git I noticed that I change branches quite a lot. This is a good thing but sometimes I am in the incorrect branch when I check things in. I needed a warning system especially when I check things into remote SVN repository. Since most of my check-ins are done from the command line it would be nice to know what branch I am on just by looking at the screen. Fortunately there is neat way to add the branch information to the Unix prompt. You can do that by overriding the PS1 variable for example:

export PS1="[\D{%Y-%m-%d} \t] \w \n$”

would generate

[2008-07-12 12:00:00] /foo/bar
$

if I am in the /foo/bar directory.

So at this point I would like the prompt to look like:

[2008-07-12 12:00:00] /foo/bar [master]
$

when I am in a master branch and prompt:

[2008-07-12 12:00:00] /foo/bar [experimental]
$

when I am in any other branch.

Here are the steps to get this working:
Prerequisites:
- ruby interpreter
- git

Steps:

  1. Create a git-ps.rb file
    green = "\033[0;32m"
    white = "\033[0;37m"
    red   = "\033[0;31m"
    current_branch = `git branch 2>/dev/null`.grep(/^\*/).first
    if current_branch
      branch_name = current_branch.gsub(/^\*\s*/,'').strip
      color = branch_name  =~ /master/ ? green : red
      unless current_branch.empty?
        puts "  #{color}[#{branch_name}]#{white}”
      end
    end
    
  2. create .ps file in your home directory:
    parse_git_branch() {
      ruby ~/git-ps.rb 2>/dev/null
    }
    export PS1="[\D{%Y-%m-%d} \t] \w\$(parse_git_branch) \n$ ”
    
  3. Include the .ps file in your .bashrc and .bash_profile by inserting following line:
    . ~/.ps
    

To activate the new prompt in your current execute command:
. ~/.ps

I hope this helps.


References

Ref: Prompt Creation
Ref: Git and Bash prompt
Ref: __git_ps1


Downloads

colored_branch_name

Using MacRuby to set Xcode project version from git

Thursday, June 19th, 2008

I have been looking into automating some of my development tasks in Cocoa/Xcode environment.  For the longest time I was using Subversion which would integrate quite well with Xcode. Recently, however, I have been exploring other version control systems.  Especially git.  Since it’s a much newer (D)VCS it does not have as much integration into systems as subversion.

I have managed to find some interesting solutions to include Git version number in Xcode project however the only actual solutions I have found are written in languages I don’t care for anymore.  Yes I can program in them but why would I want to.

So here is a quick solution written in MacRuby.

#!/usr/local/bin/macruby

git_output = `git show --abbrev-commit`
commit_version = git_output.split("\n").grep(/^commit/).first
version = commit_version.gsub(/^commit\s+(.*)\.{3}/, "\\1")
if version
  list = NSMutableDictionary.dictionaryWithContentsOfFile("Info.plist")
  list["CFBundleVersion"] = version
  list.writeToFile(’Info.plist’, :atomically => true)
end

In my final solution I intend to have an output in following format:

major.minor.revision (build)

where the “build” is going to correspond with the git commit version
and the other parts will reflect the marketing version numbers.


Ref: Shiny Frog Article Python solution
Ref: Cocoa is my Girlfriend Article Perl solution

CocoaHeads Arizona Google Group

Sunday, December 16th, 2007

It seems that Google (the search engine) has hard time associating XcodePhoenix with CocoaHeads Arizona or Cocoaheads and Phoenix and people are finding my site when searching for the group. My previous post did not mention the Google forum XcodePhoenix uses for communication so here it is:

http://groups.google.com/group/xcodephoenix

Hope to see you there.

Cocoa Heads - Scottsdale Chapter

Thursday, October 11th, 2007

Today we are organizing new Cocoa Heads chapter in Scottsdale Arizona. We hope to be the place for cocoa developers in the Greater Phoenix area.

First meeting meeting will be held at:


Target Training International LTD.
16020 N. 77th Street
Scottsdale AZ, 85260

At: 7:00pm (until 9:00pm)

More information on Cocoa Heads:
CocoaHeads Website

We will conform to the cocoaheads guidelines and schedule for meetings.

You are currently browsing the archives for the Development category.

Social Networking

Gregory Furmanek's Facebook profile
View Gregory Furmanek's profile on LinkedIn