Posts tagged as "mac":

Displaying Git Branch in the Command Line

August 13, 2008

I was hunting around looking for information about port from svn to git and getting git-svn to compile on OS X a little while back when I ran across Maddox’s explanation of branch name in command line. At the time I thought ‘Awesome!’ but I was on a mission so into del.icio.us it went to await later discover.

A couple of days ago I found the post again in my bookmarks and proceeded to spruce up my command line with the knowledge in Maddox’s post and in MacTip’s Customize Prompt on OS X article. The long and short of it is that the colors in my command prompt bother me so I cut them out of Maddox’s function and ended up with the following to lead off my ~/.bash_login.

Prompt Setup

function parse_git_branch { git branch --no-color 2> /dev/null | sed -e '/^[^]/d' -e 's/ (.*)/[\1]/' }

function gitPrompt { PS1="\h:\W\$(parse_git_branch) \u\$ " PS2='> ' PS4='+ ' } gitPrompt

I have to say I’m quite please with the new addition to my command line!

How-To: Adding Foldings to Javascript Files in MacVim

May 20, 2008

Having used TextMate for a while I have grown quite accustomed to being able to fold sections of code, particularly function declarations, so I can glance through the file to see what functions and variables I have defined. However, I recently made a totally nerd bragging rights based decision to test out MacVim. Well it wasn’t all bragging rights, being able to navigate a file without having to move my fingers from ‘home base’ would be a big plus.

The project I’m currently working on though has a couple of really large javascript files and navigating them quickly in MacVim without the foldings was something I found to be quite difficult so I started looking at the Vim help files and found the ability to create folds. Due to a disciplined use of tabs to indent code blocks :set foldmethod=indent worked fairly well but eventually it started to bug me because the of the fold was actually the first line of the content which meant the folds looked something like functionName: function() {
+ - - if (test) {
},
There had to be a better way. I realized what I wanted to do was create a fold on the line with the function declaration down to the line with the ending brace. I could not find an easy command to do this so I created a simple javascript filetype plugin (addfoldings vim plugin).

In order to get this to work I had to add filetype plugin on to my .vimrc file and I had to create the ~/.vim/ftplugin/javascript directory and drop the addfoldings.vim file into it. By default the foldings are all open but they have been created.

Update: Things are of course never as easy as they seem. The above works fine as long as you don’t add lines to the file you’re working on which is of course absurd, additionally it won’t update the foldings as you go which sort of limits the usefulness. Hopefully I’ll be able to update this to be more useful.

Working with Multiple Repositories on GitHub

May 12, 2008

Apparently there’s been quite a buzz in the open source community lately about DVCSs in general and Git and Hg in particular. Up until pretty recently (sometime in the past week) I had totally missed the boat on this. However, I spent some time reading about them in a number of places, though apparently Dave Dribin’s writings are the only ones I bookmarked. None-the-less being a good the good little open source developer I pretend to be I thought I ought to at least tinker around with one of them and see what it was all about.

In mostly a snap decision I chose Git, though Linus’ highly entertaining tech talk may have influenced me. Either way, I already had a project I was working on, it isn’t exactly a compelling open source project but I didn’t have it under version control yet and it couldn’t hurt to get it somewhere. So having decided on Git I registered for a GitHub account and created a repository for it. The whole process was simple and easy, no problems there. Basically the premise behind GitHub is like a developer’s social network (well that and free Git repository hosting), you find a project you like and you follow (watch) it or you clone (fork) it. So then I saw John Resig’s tweet that his recently released Processing.js project was being hosted on GitHub and so I decided to fork it, look at the source and play around with it a bit.

The forking process was super easy, one click after being logged in and I had forked his project. No problems there but then I wanted to pull it down to my local machine or clone it so I had a working copy and here’s where I ran into problems. Executing git clone git@github.com:bryanjswift/processing-js.git generated the following output.

Initialized empty Git repository in /Users/.../Projects/processing-js/.git/
ERROR: Permission to bryanjswift/processing-js denied to bryanjswift/bjs-wordpress.
fatal: The remote end hung up unexpectedly
fetch-pack from 'git@github.com:bryanjswift/processing-js.git' failed.

After a little research I figured out the problem was basically the wrong RSA key was being sent to GitHub and since GitHub uses the RSA key to identify you and determine if you have access to the repository or not my access was being rejected for one or the other of the repositories. Which repository depended on which RSA key was first on the list of the output from ssh-add -l

I could probably have written a pre-hook and post-hook for each of the git repositories I wanted to acess but given the nature of the man who wrote Git I knew there had to be a better solution. So I start digging around and I find a guide to multiple GitHub accounts. I realize this isn’t really the situation I’m in but it does indeed work. I set up an entry in my ~/.ssh/config for each of the two projects each looking something like

Host github-bjs-wordpress
User git
Hostname github.com
IdentityFile /Users/.../.ssh/bjs-wordpress_rsa

Happily this worked once I used the new Host entries as the ssh hosts; so git@github.com:bryanjswift/processing-js.git became git@github-processing-js:bryanjswift/processing-js.git I could now access both my repositories. Hooray! Then I was poking around my account page on GitHub and found I can enter an RSA public key for my account and not just for each repository like I had already done. So I realize my mistake was entering myself as a collaborator on each repository and because I had done it that way I had to create multiple RSA keys for myself (GitHub makes each project collaborator on each project have a unique RSA key) which caused a mess.