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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With