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?
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.
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
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
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
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