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
tabname

# Rename window to current directory name
winname

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


# Rename tab to current directory name
tn

# Rename window to current directory name
wn

Now, for opening a new tab we have:


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

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'
t

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!

Pow, meet rbenv

I just ran into a problem with Pow when using rbenv for Ruby version management whereby Rails apps were not launching properly, giving the the following error message:

Error starting application
Your Rack app raised an exception when Pow tried to run it.

Bundler::GemNotFound: Could not find ??? in any of the sources

Turns out that Pow doesn’t know anything about rbenv unless you tell it. Thomas Fuchs tweeted a solution, suggesting that you just add the following to a ~/.powconfig file:

export PATH="/Users/username/.rbenv/shims:/Users/username/.rbenv/bin:$PATH"

Kill off your Pow process (I use the Powder gem for this i.e. powder down && powder up) and all should work just fine.

I personally prefer the solution mentioned in this related Github ticket as is saves having to hardcode your home directory:

export PATH=$(rbenv root)/shims:$(rbenv root)/bin:$PATH

Happy Pow’ing.

Naming your Terminal tabs in OSX Lion

If you find yourself in the Terminal app with a bunch of tabs open, the default name of “bash” isn’t very useful when navigating between them. You can change the tab name via the UI by right clicking the tab, then clicking “Inspect Tab” and changing the window or tab names but this is somewhat long winded.

Below are a couple of bash functions I have in my “.profile” file to make this easier:


function tabname {
  printf "\e]1;$1\a"
}

function winname {
  printf "\e]2;$1\a"
}

Now you can easily name your tabs or windows with the following:


# Rename tab
tabname "Funky Tab"

# Rename window
winname "Funky Window"

Thanks to Bubu and Chris Page on the SuperUser site for the right codes.

Using Pow when developing Rails applications on OSX

I heard about Pow a while ago which is “a zero-config Rack server for Mac OS X” but never got around to giving it a go. I’ve just installed it and can instantly see that it is going to make developing with Rails (or any Rack app) a whole lot nicer, especially when dealing with apps that use subdomain account keys.

If you’ve not tried it yet, head over to the Pow website and get it installed with:

curl get.pow.cx | sh

Happy new year everyone!

Ruby Causing MacBook Pro to Run Hot

The past couple of days the fan on my MacBook Pro has been constantly on and battery usage down to around a third. Launching Activity Monitor, it showed 3 Ruby processes all at 100% CPU usage. The solution was to force quit these processes and within seconds, the fan slowed up and the battery indicator went up. Force quitting these processes didn’t affect anything I was doing with Rails or IRB so I guess they were just stray processes.

If anyone else gets the same problem, just launch Activity Monitor which lives in the /Applications/Utilities folder, click the CPU tab if not already selected, select processes with a process name of “ruby”, click “Quit Process” and then select “Force Quit”. Just selecting “Quit” wouldn’t work for me hence the “Force Quit”.

I hope this saves someone else the head-scratching as to why their Mac is running hot.

Proprietary CSS rules – Are we returning to 1995?

Call me a cynic, but posts like this one on the Surfin’ Safari blog worry me a little. Let me explain…

I don’t know if anyone remembers back to the days of Netscape 4 and Explorer 3.5? – It was a time of table based layouts and browser sniffing. Each browser had it’s own “feature” set and this resulted in hacks galore, for example Netscape had “Layers” but Explorer didn’t, Explorer had feature X but Netscape didn’t.

Along came Web Standards and the likes of Jeffrey Zeldman fighting for a standards based approach to web development. Over a decade on, it looks like were finally getting there as even Microsoft slowly start to get things right with IE7.

As cool as the CSS Transform stuff looks, I can’t help but think we’re stepping right back into 1995.

What does everyone else think?

Autotest Growl Fail/Pass Smilies

John Nunemaker posted a handy tip on “setting up autotest to work with Growl”:http://railstips.org/2007/7/23/autotest-growl-pass-fail-notifications

I use this all the time now however I didn’t like the ugly smilies (call me shallow if you like). I used “Wolfgang Bartelme’s”:http://bartelme.at “Smily Devkit”:http://bartelme.at/journal/archive/smiley_devkit to make a couple of PNG’s slightly more pleasing to the eye.

p=. !http://thelucid.com/files/fail.png(Autotest Fail image)!
!http://thelucid.com/files/pending.png(Autotest Pending image)!
!http://thelucid.com/files/pass.png(Autotest Pass image)!

The zip file can be downloaded here: “autotest_images.zip”:http://thelucid.com/files/autotest_images.zip

*Update* 17-08-07: Added ‘pending’ image for RSpec as requested by Aslak Hellesoy