Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening a new terminal tab in OSX(Snow Leopard) with the opening terminal windows directory path

I've been Googling for a while looking for a simple way to do this, and I can't find one.

I have a custom terminal environment set up (zsh) with various aliases and functions to make things easier. One thing I keep running into is that I will quickly APPLE-t to create a new tab and then type a command relative to the path of the terminal window I was just in. This invariably fails because the path of the new tab is ~/ instead of whatever I was just using! Any ideas for a script to set the directory path of the new terminal tabs to the directory path of the opening tab?

Any help most appreciated.

Ian

like image 470
i0n Avatar asked Oct 19 '09 14:10

i0n


2 Answers

I have a couple of scripts I use:

dup (New window with the working dir):

#!/bin/sh
pwd=`pwd`
osascript -e "tell application \"Terminal\" to do script \"cd $pwd; clear\"" > /dev/null

and tup (New tab with the same working dir):

#!/bin/sh

pwd=`pwd`
osascript -e "tell application \"Terminal\"" \
    -e "tell application \"System Events\" to keystroke \"t\" using {command down}" \
    -e "do script \"cd $pwd; clear\" in front window" \
    -e "end tell"
    > /dev/null
like image 155
Gavin Brock Avatar answered Oct 13 '22 20:10

Gavin Brock


One other solution without scripting is iTerm2, which has this feature built in. It has even more features that make it worth checking out too.

like image 36
xer0x Avatar answered Oct 13 '22 19:10

xer0x