Ttab
macOS and Linux CLI for opening a new terminal tab/window, optionally with a command to execute and/or display settings
Install / Use
/learn @mklement0/TtabREADME
Contents
- ttab — programmatically open a new terminal tab or window
- Installation
- Examples
- Usage
- License
- Changelog
ttab — programmatically open a new terminal tab or window
A CLI for Unix-like platforms that programmatically opening a new terminal tab/window in one of the following terminal applications, optionally with a command to execute and/or a specific title and specific display settings (profile).
- On macOS: either
Terminal(the default terminal emulator) or popular alternativeiTerm2. - On Linux, Gnome Terminal (
gnome-terminal), thanks to a contribution by @ksvirsky. - Note:
ttabdoes not support Windows; consider using the Windows Terminal-basedwttabutility there.
Note: iTerm2 and gnome-terminal support is currently not covered by the automated tests run before every release.
Installation
Important: On macOS, irrespective of installation method, Terminal / iTerm2 (iTerm.app) needs to be granted access for assistive devices in order for ttab to function properly, which is a one-time operation that requires administrative privileges.
If you're not prompted on first run and get an error message instead, go to System Preferences > Security & Privacy, tab Privacy, select Accessibility, unlock, and make sure Terminal.app / iTerm.app is in the list on the right and has a checkmark.
For more information, see Apple's support article on the subject.
Installation via Homebrew (macOS only)
With Homebrew installed, run the following:
- Initial installation:
brew tap mklement0/ttab https://github.com/mklement0/ttab.git
brew install mklement0/ttab/ttab
- Later updates:
brew upgrade mklement0/ttab/ttab
Note:
- The Homebrew version may lag behind the npm registry version if later versions relate solely to the Linux-only Gnome Terminal functionality.
- To remove
ttablater, runbrew rm ttab.
Installation from the npm registry
With Node.js installed, install from the npm registry:
-
Initial installation:
[sudo] npm install ttab -g -
Later update:
[sudo] npm upgrade ttab -g
Note:
- Whether you need
sudodepends on how you installed Node.js and whether you've changed permissions later; if you get anEACCESerror, try again withsudo. - The
-gensures global installation and is needed to putttabin your system's$PATH. - To remove
ttablater, run[sudo] npm rm ttab -g.
Manual installation
- Download this
bashscript asttab. - Make it executable with
chmod +x ttab. - Move it to a folder in your
$PATH, such as/usr/local/bin.
Examples
# Open a new tab in the current terminal window.
ttab
# Open a new tab in a new terminal window.
ttab -w
# Open new horizontal split tab in the current terminal window:
ttab -h
# Open new vertical split tab in the current terminal window, changing the path to the
# given path, but without checking the presence of the target directory:
ttab -v -i -d "$HOME/Library/Application Support"
# Open a new tab and execute the specified command before showing the prompt.
ttab ls -l "$HOME/Library/Application Support"
# Open a new tab and execute the specified command *after a delay* of 0.8 secs,
# to accommodate shells with lengthy initialization-file processing.
# Note: You may preset the delay via environment variable TTAB_CMD_DELAY
ttab -l 0.8 ls -1
# Open a new tab and execute *multiple* commands in it - note how the entire
# command line is specified as *single, quoted string*.
ttab 'git branch; git status'
# Open a new tab, switch to the specified dir., then execute the specified
# command before showing the prompt.
ttab -d ~/Library/Application\ Support ls -1
# Open a new tab with title 'How Green Was My Valley' and settings 'Grass'.
# See the note re use of -t in iTerm2 below.
ttab -t 'How Green Was My Valley' -s Grass
# Open a new tab and execute the specified script before showing the prompt.
ttab /path/to/someScript
# Open a new tab, execute the specified script, and exit.
ttab exec /path/to/someScript
# Open a new tab, execute a command, wait for a keypress, and exit.
ttab 'ls "$HOME/Library/Application Support"; echo Press a key to exit.; read -rsn 1; exit'
# Open a new tab in iTerm2 (if installed).
ttab -a iTerm2 echo 'Hi from iTerm2.'
# Execute the command in the current tab of the current terminal window:
ttab -c 'ls "$HOME/Library/Application Support"'
Usage
Find concise usage information below; for complete documentation, read the manual online, or, once installed, run man ttab (ttab --man if installed manually).
$ ttab --help
Opens a new terminal tab or window, on macOS in either Terminal.app or
iTerm2.app; on Linux in Gnome Terminal, if available.
ttab [-w|-v|-h|-c] [-i] [-s <settings>] [-t <title>] [-q] [-g|-G] [-d <dir>] [<cmd> ...]
-w Open new tab in new terminal window.
-v iTerm only: create a new vertical split
-h iTerm only: create a new horizontal split
-c Terminal/iTerm only: do not open any new window or
tab, run in the current tab of the current window.
-i Suppress up-front verification of the existence of
the target directory specified via the -d option.
-s <settings> Assign a settings set (profile).
-t <title> Specify title for new tab.
-q Clear the new tab's screen.
-g Terminal/iTerm only: create in background (don't
activate application).
-G Terminal/iTerm: don't activate new tab and create in
background.
gnome-terminal: don't activate new tab, except with -w.
-d <dir> Specify working directory; -d '' disables inheriting
the current dir. in Terminal/iTerm.
-l <secs> Terminal/iTerm only: delay startup command submission;
may be preset via env. var. TTAB_CMD_DELAY
-a Terminal | iTerm Open the new tab in the given terminal app on macOS.
<cmd> ... Command to execute in the new tab.
"<cmd> ...; ..." Multi-command command line (passed as single operand).
Standard options: --help, --man, --version, --home
Note to iTerm2 users: The -t option for specifying a title only works if
the new tab's active profile is configured to show the session name in the
title, which can be configured via the Preferences dialog as shown by
@francis-lookback here.
License
Copyright (c) 2015-2024 Michael Klement mklement0@gmail.com (http://same2u.net), released under the MIT license.
Acknowledgements
A thank you to all contributors to this repo, especially the following major ones:
This project gratefully depends on the following open-source components, according to the terms of their respective licenses.
npm dependencies below have optional suffixes denoting the type of dependency; the absence of a suffix denotes a required run-time dependency: (D) denotes a development-time-only dependency, (O) an optional dependency, and (P) a peer dependency.
npm dependencies
<!-- DO NOT EDIT THE NEXT CHAPTER and RETAIN THIS COMMENT: The next chapter is updated by `make update-readme/release` with the contents of 'CHANGELOG.md'. ALSO, LEAVE AT LEAST 1 BLANK LINE AFTER THIS COMMENT. -->Changelog
Versioning comp
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
