Update . This answer gained popularity based on the shell function described below, which still works with OSX 10.10 (except for the -g option).
However, a more fully functional, more reliable, tested version of the script is now available in the npm registry as CLI ttab , which also supports iTerm2 :
If you have Node.js installed, just run:
npm install -g ttab
(depending on how you installed Node.js, you may need to add sudo ).
Otherwise, follow these instructions .
After installation, run ttab -h for a summary of usage or man ttab to view the manual.
Based on the accepted answer, below is the bash convenience function to open a new tab in the current terminal window and, optionally, execute a command (as a bonus, there is a variant function for creating in a new window).
If a command is given, its first token will be used as the new tab header.
Sample Calls:
# Get command-line help. newtab -h # Simpy open new tab. newtab # Open new tab and execute command (quoted parameters are supported). newtab ls -l "$Home/Library/Application Support" # Open a new tab with a given working directory and execute a command; # Double-quote the command passed to `eval` and use backslash-escaping inside. newtab eval "cd ~/Library/Application\ Support; ls" # Open new tab, execute commands, close tab. newtab eval "ls \$HOME/Library/Application\ Support; echo Press a key to exit.; read -s -n 1; exit" # Open new tab and execute script. newtab /path/to/someScript # Open new tab, execute script, close tab. newtab exec /path/to/someScript # Open new tab and execute script, but don't activate the new tab. newtab -G /path/to/someScript
CAVEAT . When you start newtab (or newwin ) from a script, the initial working folder of the script will be the working folder in the new tab / window, even if you change the working folder inside the script before calling newtab / newwin - pass eval with the cd as a workaround (see example above).
Source code (for example, paste in your bash profile):
mklement0 Aug 27 '12 at 18:52 2012-08-27 18:52
source share