Bfec5f7d1a4aaafc5a2451be8c42d26a

Here's a small script I wrote to open a new tab in iTerm in the current directory. I place this in my .bash_profile and use it a lot to start Rails server and open a new tab to work in: tab; script/server
Know any better way of doing this ?

Btw, I'm also introducing a new language in here: Bash :) Hope you like it!

Also, I know the server is bloody slow, sorry for that. I'm migrating to a new and absurdly fast server at the moment. Hang on!

1
2
3
4
5
6
7
8
9
10
11
12
tab() # new tab from current dir
{
osascript -e "
tell application \"iTerm\"
 tell the first terminal
  launch session \"Default Session\"
  tell the last session
   write text \"cd $(pwd)\"
  end tell
 end tell
end tell"
}

Refactorings

No refactoring yet !

B8d457d2c39911ea4c74ba7d66b9c3f7

Marco Valtas

October 10, 2007, October 10, 2007 05:00, permalink

No rating. Login to rate!

Macournoyer, I tried your function and it opens the server on my window then launches me to another tab. I prefer stay in my tab and launch the process in another tab. After some digging I came up with the code bellow, the difference in the command call is that you don't need use the ";".

So, what was: tab; script/server
Now should be: tab script/server

The only thing I could not solve is that iTerm changes the tab on a launch, so I had to bring it back with a "select session" call.

[bash]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
tab()
{
        osascript -e "
        tell application \"iTerm\"
         tell the first terminal
          set currentSession to current session
          launch session \"Default Session\"
          tell the last session
           write text \"cd $(pwd)\"
           write text \"$*\"
          end tell
          select currentSession
         end tell
        end tell"
}
Bfec5f7d1a4aaafc5a2451be8c42d26a

macournoyer

October 10, 2007, October 10, 2007 12:25, permalink

No rating. Login to rate!

great idea Marco, indeed it looked strange that is was launching in another tab, thx for the change!

Your refactoring





Format Copy from initial code

or Cancel