Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am often working in a process in the Terminal and I've set some variables and used cd and so forth. Then I'd like to open another Terminal window from there. Is there any way to do this?

share|improve this question
add comment

4 Answers

up vote 6 down vote accepted

You could use this little script to do what you want:

#!/bin/sh 
osascript <<END 
tell app "Terminal" to do script "cd \"`pwd`\"" 
END

place it in one of the folders in your path, make it executable (chmod +x filename) and run rehash. You can then run the name of this script to open a new terminal window in the same directory.

Src

share|improve this answer
    
I'm using this, but how would I get it to work without having to run the script. I would like new terminal windows to inherit the last place I cd'ed to. Any easy ideas, or should I open a new question? –  Yar Jul 19 '10 at 17:58
add comment
open -a Terminal .

should do the trick. It simply opens the current directory . with the application Terminal. Of course, you can use any relative or absolute path instead of . such as :

open -a Terminal ..           # Parent directory
open -a Terminal ~/Documents  # User's documents
open -a Terminal /Library     # System library
share|improve this answer
    
awesome and necessary addition to this question. AT the time, I had bigger goals, but now this is more than sufficient. –  Yar Sep 18 '13 at 16:24
    
So in my .zshrc I have alias shell_here='open -a terminal .' Fun! –  Yar Sep 18 '13 at 16:29
add comment

What you could do is the following.

Get the current environment in your clipboard:

env | pbcopy

Open up a new Terminal window and export those environment variables

for env in `pbpaste`; do export $env; done

And to ease the process, you could always alias it, like so

alias get_env="env | pbcopy"
alias set_env="for env in `pbpaste`; do export $env; done"

So that all you have to do is

get_env Command+N set_env

share|improve this answer
    
Nice +1. I guess this could be remixed with John T's answer to get one single script. –  Yar Apr 3 '10 at 17:58
    
@dex, thanks for this. I've mashed it together with John T's solution, but I'm getting some errors in the pbpaste part (though it works). syntax error near unexpected token do'` –  Yar Apr 3 '10 at 19:18
    
@yar it might have to do with the fact that I made a typo ("or" instead of "for") in the second alias line. Sorry about that. –  Loïc Wolff Apr 3 '10 at 20:17
    
the problem is that the $env cannot be blank and also some other ones do not work, like, TERM_PROGRAM=Apple_Terminal. I guess they all need to have a $. –  Yar Apr 4 '10 at 1:46
    
Actually, this only seems to work. the pwd doesn't actually change the directory, it just confused the pwd! –  Yar Apr 5 '10 at 12:32
show 1 more comment

To open a new Terminal window you can do open -n /Applications/Utilities/Terminal.app or also /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal & Though I don't know if they will accept an argument such as cd ~/Documents/ Both these make completely new instances though, so to go between them on the keyboard you have to do cmd+tab and not cmd+` And if you are going to cmd+tab it always put's the new instance at the end of the queue, so you may have to do shift+cmd+tab

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.