Archive

Archive for the ‘mac’ Category

GIT Merge and Diff with p4merge on Mac

September 27, 2011 6 comments

Git is my favorite SCV system up to now and most probably will be in the future. Besides of many great features is has pretty good automatic merge tool, that is able to solve conflicts, but not all of them. I found p4merge tool much better in case of automatic merging and manual solving the most hard conflicts. Is is very simple to mix together those two things to have the best from both of them and now I will show you how to do that.

First of all, you have to install p4merge tool. Go to p4merge tool download page, choose “Browse by platform” tab, pick your platform (in my case it was Macintosh) and download P4V: Visual Client. After downloading, open dmg file and copy p4merge tool to Applications folder in your Dock.

Second step is to create two simple bash scripts: p4merge and p4diff,  that will be executed when git needs merge or diff tool. Create these scripts in directory that is in your’s system PATH (i.e. /usr/local/bin/).

p4merge

#!/bin/sh
/Applications/p4merge.app/Contents/MacOS/p4merge $*

p4diff

#!/bin/sh
[ $# -eq 7 ] && /usr/local/bin/p4merge "$2" "$PWD/$5"

Don’t forget to add executable mode/flag to these scripts.

After p4merge and scripts are ready it’s time to configure global git settings. Edit ~/.gitconfig file and put following configuration there for merging:

[merge]
    tool = p4merge
    keepBackup = false
[mergetool "p4merge"]
    cmd = p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
    keepTemporaries = false
    trustExitCode = false
    keepBackup = false
[diff]
    external = p4diff

If you don’t want to use p4merge as diff tool, just comment (using # character) [diff] section. Sometimes it’s faster for me to use command line diff instead of visual one.

Now, when you type “git diff” or “git mergetool” in your’s project directory, p4merge tool will be started.

Categories: mac, source control Tags: , , , , ,

Print TODO/FIXME Comment as Warning in XCode

July 12, 2011 Leave a comment

When I’m implementing new functionality I start with the general design and then I’m implementing newly created classes and methods. Sometimes I leave a method or two for later implementation (i.e. after creating unit test for this method) and almost always putting comment:

// TODO: nice comment here

It already happened to me, that I left this comment unnecessary or (the worst case scenario) I forgot to implement this TODO part 😦 To get rid of these mistakes you can add Run Script phase in Build Phases of your project’s target with some nice shell command. To do this, click on your target, move to Build Phases tab and in right-bottom corner click Add Build Phase and choose Add Run Script. Leave shell as it is and in the content of the script paste following two lines:

KEYWORDS="TODO.*:|FIXME.*:|\?\?\?.*:|\!\!\!.*:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.mm" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"
At the end of second line you can add i.e.:
| grep -v ExternalSources
This will prevent from printing warnings for TODO/FIXME comments in file paths containing “ExternalSources”. It’s in case you use third party source code that still needs some work to be done 🙂
The latest revision of this script can be found at my github repository: todo xcode gist
Categories: mac, programming Tags: , ,

Moving Files in XCode

July 12, 2011 2 comments

Couple of times I made silly mistake of creating new files in XCode project not in the place I want them to be in filesystem. Groups and “real” folders still confuse me. When you have such file in your project that is in correct group, but not in correct folder on the disk and you don’t want to remove it’s reference and add the same file again I have two steps solution for you.

First you open Finder (or any other file commander tool) and move the file to the correct location. When you will open XCode you will see that this moved file is red now (this is expected behavior, XCode cannot find this file under old location):

What you have to do is to highlight this file and open File Inspector (menu View -> Utilities -> File Inspector or by keyboard shortcut <command> + <option> + <1>). Just under Location combo box there is specified current location for this file. Hit the little folder icon on the right and choose the new path of the moved file:

And that’s it. The drawback of this solution is that you have to repeat this steps for each file you want to move, but if you have plenty of them, probably it’s better to remove references and add them again.

Categories: mac, programming Tags:

Git Branch in Bash Prompt

January 8, 2011 Leave a comment

I like to work in text console and I’m usually using bash and git for my projects. When I have to switch between branches couple of times during the day and made changes I have to be careful which brach I have currently checked out.  It can be done quickly by just typing “git branch”, but  I don’t like to type it every time I need to do something.

One of the solution is displaying current git branch in bash prompt. My fouvrite one is as follows:

PS1='\[\e[32m\]\w `git branch 2>/dev/null | grep -e '\''^*'\'' | sed -E '\''s/^\* (.+)$/(\1) /'\''`\n\$\[\e[0m\] '

The interesting part is between “`” marks. This command lists all git branches, greps only the current one (with asterisk) and creates string with sed.

This prompt will not print anything about git branches if you are currently in the folder not handled by git repository. Normally above prompt will look like this:

But when you will enter directory under git repository it will look like this:

If I will modify my prompt in the future, you can find the latest version here.

Categories: linux, mac, source control Tags: , , ,

Screenshots on Mac

December 8, 2010 Leave a comment

Maybe you didn’t noticed, by my previous post had at last screenshot that was made properly.

Here is a list of keyboard shortcuts that will do the trick:

  • Command+Shift+3
    Take a screenshot of the screen, and save it as a file on the desktop
  • Command+Shift+4, then select an area
    Take a screenshot of an area and save it as a file on the desktop
  • Command+Shift+4, then space, then click a window
    Take a screenshot of a window and save it as a file on the desktop
  • Command+Control+Shift+3
    Take a screenshot of the screen, and save it to the clipboard
  • Command+Control+Shift+4, then select an area
    Take a screenshot of an area and save it to the clipboard
  • Command+Control+Shift+4, then space, then click a window
    Take a screenshot of a window and save it to the clipboard

In Leopard, the following keys can be held down while selecting an area (via Command+Shift+4 or Command+Control+Shift+4):

  • Space, to lock the size of the selected region and instead move it when the mouse moves
  • Shift, to resize only one edge of the selected region
  • Option, to resize the selected region with its center as the anchor point

And now, when you think that I am master in Mac keyboard shortcuts I’ll disappoint you. This text was completely copied from MacRumors web page 🙂 You will find there also formats of screenshots, creating screenshot from terminal and third party applications and many. many more other guides.

Categories: mac Tags: