OSX Terminal – Tab and window shortcuts

In a previous post, I shared a tip on Naming your Terminal tabs in OSX Lion. I’ve been meaning to share some additional shortcuts that I use day-to-day for opening new tabs and renaming them via the command line.

The workflow

We can rename tabs and windows as before:

# Rename tab
tabname "Funky Tab"
# Rename window
winname "Funky Window"

Or, leave out the name to base it the current directory:

# Rename tab to current directory name
# Rename window to current directory name

…and to save typing, these are aliased as ‘tn’ and ‘tw’, so this will do the same:

# Rename tab to current directory name
# Rename window to current directory name

Now, for opening a new tab we have:

# Open new tab, cd into same directory as current tab and name it

By default this will open a new tab, cd into the same directory as the current tab and name it based on it’s directory. You can optionally include a path:

# Open new tab, cd into specified directory and name it
tab ./path/to/directory

Of course, there is a lazy version of creating tabs too:

# Shortcut for 'tab'

The code

To get this functionality, just drop the following into your ~/.profile file:

function tabname {
  # Will use current dir name if called without arg.
  printf "\e]1;${1-$(basename `pwd`)}\a"
function winname {
  # Will use current dir name if called without arg.
  printf "\e]2;${1-$(basename `pwd`)}\a"
function tab {
  # Will cd into current dir if called without arg.
  osascript -e 'tell application "Terminal"' \
            -e 'tell application "System Events" to keystroke "t" using {command down}' \
            -e "do script \"cd `pwd` && cd ${1-.} && tabname && clear\" in front window" \
            -e 'end tell' > /dev/null
alias t='tab'
alias tn='tabname'
alias wn='winname'

See the Gist here.
Happy tabbing!

Git add -A and git commit one liner

When working with Git, I often find myself typing:

git add -A && git commit -m "My commit message"

This stages any changes including new files (which "git commit -am" doesn’t), marks any files that have been deleted from the working copy as removed and commits to the repository.
Following a quick Google search, and thanks to this handy git alias article, I created a “ca” (commit all) alias using:

git config --global alias.ca '!git add -A && git commit'

Now committing all changes is as simple as:

git ca -m "My commit message"

This is a good solution, however I prefer adding the following function to my ~/.profile file:

function gca {
  git add -A && git commit -m "$1"

Which gets us to:

gca "My commit message"

Embracing perfectionism as a long term goal

I’ve suffered for a long time with a condition known as perfectionism. It’s a debilitating disorder that hampers productivity through a constant pursuit of idealism.
There are many problems that come with being a perfectionist. Firstly, there is the aforementioned productivity impairment. But also, it’s hard to be happy with anything you produce or anything you’ve achieved in life, as you always believe you could have done better. This does have a side benefit of driving you toward your goals, the problem being that as a perfectionist, your goals are always evolving and often unrealistic.
I’ve fought with the productivity/perfectionism conundrum for a while now and have come to terms with the fact that I will always be a perfectionist at some level. Both my parents are perfectionists, it’s in my DNA. Instead of fighting this innate condition as I have done over the past few years, I’ve recently found a way of embracing perfectionism by treating perfection as a long term goal. So, what do I mean by this?
Let’s take an oil painting as an example. First the artist starts with a thick brush and large blocks of colour to give a general overview of his subject. At this stage he is much more agile and can easily change direction should he need to. Later, after the paint has dried a little, he adds more detail. He repeats this process until he is working with tiny brushes, on the minutest details. There is a great deal to be learned from this technique.
I am suggesting the long term goal of a perfect project, without getting bogged down by tiny details at the outset. Do just enough to fulfil the project requirements with a view to tweak (and perfect) further down the line; there is no point perfecting something that is subject to change. Giving yourself permission to let stuff go until later is the key, however it’s extremely important that this tweaking phase is included in the overall project plan.
Perfectionism is fine as a long term goal, just don’t let it hinder in reaching those goals.

Git – setting up a remote repository and doing an initial push

There is a great deal of documentation and many posts on Git out there, so this is more of a note to self as I keep forgetting the steps needed to set up a remote repository and doing an initial “push”.
So, firstly setup the remote repository:

ssh git@example.com
mkdir my_project.git
cd my_project.git
git init --bare
git update-server-info # If planning to serve via HTTP

On local machine:

cd my_project
git init
git add *
git commit -m "My initial commit message"
git remote add origin git@example.com:my_project.git
git push -u origin master

Team members can now clone and track the remote repository using the following:

git clone git@example.com:my_project.git
cd my_project


To have your terminal prompt display what branch you are currently on in green, add the following to your ~/.bash_profile (I have my current directory displayed in cyan):

function git-branch-name {
  git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
function git-branch-prompt {
  local branch=`git-branch-name`
  if [ $branch ]; then printf " [%s]" $branch; fi
PS1="\u@\h \[\033[0;36m\]\W\[\033[0m\]\[\033[0;32m\]\$(git-branch-prompt)\[\033[0m\] \$ "

New web-based GTD productivity application

Finally I can mention it. At SonicIQ we’ve been working on a web-based “GTD”:http://davidco.com application. Today the teaser site went live at “propelr.com”:http://www.propelr.com.
If you are are into “GTD”:http://davidco.com, life hacks or productivity in general head over to “propelr.com”:http://www.propelr.com. for a sneak peek!