mklement0 / ttab Goto Github PK
View Code? Open in Web Editor NEWmacOS and Linux CLI for opening a new terminal tab/window, optionally with a command to execute and/or display settings
macOS and Linux CLI for opening a new terminal tab/window, optionally with a command to execute and/or display settings
iTerm is quite popular among devs who work on OS X. But ttab
gives you error:
79:307: execution error: System Events got an error: Can’t get application process "Terminal". (-1728)
It would be great if iTerm can be supported.
As reported by @barankyle here:
The design intent of ttab
is to run commands specified on the command line in an instance of the user's default shell.
This means that you should be able to abort such startup commands by pressing Ctrl-C, without terminating the shell session as a whole.
While this works as intended on macOS, with Gnome Terminal on Linux the shell session is currently terminated, thereby (typically) closing the new tab.
Note that an unavoidable limitation of using ttab
with Gnome Terminal is that keeping the session open can only be emulated: that is, for technical reasons a new instance of the user's default shell must be created that replaces the instance that ran the startup command - as such, the original shell's environment isn't fully preserved.
When stringing a chain of commands together ttab consistently opens new windows instead of tabs, any idea why this would happen?
For example:
ttb -t 'title1' <some cmd> && ttab -t 'title2' <some cmd> && sleep 5 && ttab -t 'title3' <some cmd>
The title3 tab will be opened in a new terminal window rather than a tab.
nice work, I am writing a library and the library writes out log files and I give the user the option to tail those files. Instead of making the user find those files and then write a command four times to tail each one, my library just has a single command and without any args will open up the four windows on the behalf of the user.
however, the problems I have are:
Please let me know if you think your lib can help - I would also really love to see *nix support and full support for iTerm2! thanks!
*they way I open up new windows is with:
I run this with a node child_process:
#!/usr/bin/env bash
open -a Terminal.app `dirname $0`/tail.sh
which in term runs this:
#!/usr/bin/env bash
tail -F ${FILE_TO_TAIL}
My iTerm2 settings had it excluded from the Dock (Appearance/General/Exclude from Dock and Tab Application Switcher)
This created an issue, that the ttab stopped working correctly, essentially nothing happened when you tried to use a command except for --help.
Removing the setting solves the issue.
Certain commands are not (AFAIK) possible with ttab, because of precedence rules.
ttab -t 'code & git' (git branch; git status)
ttab -t 'code & git' (git branch && git status)
It might seem that putting quotes around the command would fix this, passing it all to ttab as a single argument that could be unpacked before being issued to the shell, but it does not work.
Allowing the command and its arguments to be either single or double quoted (but not requiring it!) would be very helpful, as it would allow commands like those given above to succeed.
I'm using iTerm2 version 3.4.12.
When I run my script the parameters of the script are changed during the process.
Above is the image of the current output. The task is supposed to run a 'npm run serve' command. However, the directory is changed when the script is run. There's a semicolon after the user directory /users/USERNAME/folder/folder; npm run serve
Is it possible to, for example:
ssh somesite
cd some/dir
./somescript
Seems that it opens ssh but then doesn't fire the remaining scripts..
ttab 'ssh somesite; cd /home/somewhere'
I'm having the issue below. It went from working to not working on a project seemingly after changing my project's branch and reinstalling node_modules but that hasn't changed the package version of ttab or the way it's being used
OSX bash (zsh. Tried both but same issue)
ttab v0.7.2 (tried v0.7.3 but same issue)
kTHIS_NAME=${BASH_SOURCE##*/}
^
SyntaxError: Unexpected token '{'
I was trying to make a script that opens a tab and runs a command for the user using exec. It works fine right after iterm2 is launched. However, once the tab is closed (when the command ends) and I run ttab again, it just hangs forever. I don't see anything in ps aux that would be killable as a hung up task so I'm at a loss on what it could be.
travisb at traviss-mbp in ~ × @12:19
> ttab -w exec sudo lsyncd /Users/travisb/Code/local/ims_v3/sync.lua
travisb at traviss-mbp in ~ @12:20
> ttab exec sudo lsyncd /Users/travisb/Code/local/ims_v3/sync.lua
^C
travisb at traviss-mbp in ~ × @12:22
It would make the installation even easier if the homebrew formula for ttab
was published to a homebrew tap.
When trying to use ttab
via iTerm2:
0:7: execution error: Can’t get application "iTerm". (-1728)
139:145: syntax error: Expected end of line but found class name. (-2741)
macOS: 10.12.6
Node: v8.6.0
Installed with: npm i -g ttab
Would love for this to support tmux, which currently I use with Alacritty. Happy to be assigned this, to act as a reminder for me to get this done.
Hi, I just started using ttab and it looks like when I pass in ttab -G -t 'Datastore Emulator' gcloud beta emulators datastore start
, the new tab still receives focus. I've attached a gif, to clarify
it may be a little easier to follow here
This is admittedly a minor cosmetic issue, but hopefully it's a simple change.
When gnome-terminal is in use, and the change that was added last week to re-execute $SHELL when the running process closes is triggered, the new shell doesn't have the title that was applied to the original tab. It would be nice if the title could be re-applied.
It would be great if ttab
would automatically start an iTerm2 instance if it didn't already exist.
Hello,
before I was able to set iTerm2 title with -t switch but it at some point stopped working.
I am not sure if after iTerm2 or ttab update.
now if I do ttab -t abc
a new tab title says bash
ttab
77:85: syntax error: Expected “,” but found identifier. (-2741)
Greetings!
I use ttab
for development purposes on my macOS machine. I've noticed that when pushing my node js build for production on a node:carbon (linux) docker image, ttab
causes the build to fail because [the] platform "linux" is incompatible with this module
. Would it be possible to throw this error only when used rather than when installed ( or to support Linux #5 )?
Cheers ✨
Scenario: I have a script that edits a few files and runs the npm project. If it was all part of one script, i could trap the interrupt (ctrl+c) and perform a custom clean up function that may checkout or delete files.
Problem: Since, on using ttab, a new window or tab is opened, i can't assign the same trap function to the new tab or window since the context is lost. Hence, can't perform clean up on interruption.
Proposal: Maybe if there is a way to attach a function or set of actions when an interrupt happens.
# trap ctrl-c interrupt and call cleanup
trap ctrl_c INT
ctrl_c(){
tput setaf 3; echo -e "\nTerminating Process...\n"; tput sgr0
cleanUp()
}
this is how i was trapping the interrupt.
cleanUp(){
tput setaf 3; echo "Cleaning up before exiting"; tput sgr0
git -C "./project-dir/" clean -df
git -C "./project-dir/" checkout .
tput setaf 2; echo "Undid changes. Exiting..."; tput sgr0
exit
}
this is the clean up function, that would checkout . to remove changes to tracked files and delete untracked files
The script you provided in this stack overflow post showed opening a split tab, which would be a great feature for ttab. I saw you mention it isn't a feature yet - does that mean there is already a plan to make it a feature?
Thanks for making this amazing tool
Have opened an issue with warp here: warpdotdev/Warp#3183
Essentially, it would be great if ttab also opened tabs in warp, as it's a great modern terminal
I need such functionality in my windows environment.but this isnt supporting windows or linux.giving error in installation as
Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
Is there any plan to add it or not?
is this behavior possible?
If i start project with ttab, closing the tab warns me that the application will terminate but it doesn't. It remains running and holds on to the port, preventing me from restarting the application
ttab 'npm run dev'
If i start the application with out ttab, closing the tab warns me that the application will terminate and it actually does.
npm run dev
Can you provide any guidance for ensuring that my sub-command does exit?
Do you have plans to make this work with https://github.com/felixse/FluentTerminal?
Using Terminal.app automatically causes a new tab to inherit the calling tab's working dir.
This doesn't work in iTerm2 as of v0.4.0.
Workaround: add -d .
Note that the problem doesn't surface when you specify -w
to open the tab in a new window, because an explicit cd
command is issued in that event.
Quite frequently, in the macOS Ventura beta, ttab <command>
will result in the command being run in the current window, and a new, empty tab being opened. Happens about half the time.
Would be great if you could define your preferences (like iTerm2) in a config file if one exists. For example ~/.ttabrc
When I just run ttab
, the frontmost terminal window doesn't open a new tab until I select the Terminal menu bar with my mouse.
(FWIW, when running ttab -w
, a new Terminal window opens just fine). Not familiar with apple script, but using the macOS script editor to manually run the generated apple script (from --dry-run
) has the same results as above.
I have enabled Accessibility for Terminal.app in Security & Privacy settings, and I'm on macOS 10.12.4.
Any help debugging would be appreciated. Absolutely loved this utility when it was working to help manage tabs and windows in scripts.
Dear Mr. Klement,
Thank you very much for the ttab utility! It is an exceptional piece of work both implementation- and design-wise. In fact, I have just forked the whole project with the intent of using it as a template for my next one, lint. The lint project will be solely my own responsibility, but I must and very much willing to give full credit to the project of yours I am basing it on. And I am not sure how to properly reflect it in the LICENSE.md file. Please let me know if the following line will be satisfactory:
Copyright (c) 2017 Alec Missine [email protected], released under the MIT license. Based off of ttab.
Thank you,
Alec
Hi,
I apologize if this has already been resolved. I can use ttab just fine. The only thing that bothers me is that I have to use Ctrl-C to return to the command prompt after I open tab in current window. Otherwise, it just hangs.
Thanks for all the effort put into this. It's much appreciated :)
When invoking the command below:
ttab -d ~/Developer/docker_es -g -t 'Docker ES' docker-compose up es01
The tab opens and briefly sets the title to "Docker ES", after which the title is immediately replaced with "cd /Users/username/Developer/docker_es".
I've turned off all of the Terminal preferences that relate to Window to Tab titles.
Am I doing it wrong?
sleep 10; ttab -G top &
While using different app, The ttab process will briefly steal focus and become the frontmost terminal for a moment then return to the other app.
It will get closer to perfect if ttab has function to close the opened tab/window.
Hi there,
I know this is a module for mac, but could you please not throw an exception on installation when the OS is not a Mac?
Whenever I try to install my dependencies, I cannot complete the installation, because it throws me an error in the process of installing because I'm not on a mac and then exits the installation.
I am definitely sure this is ttab, because it works fine when i remove the dependency on a ubuntu distro and then intall the dependencies again.
Maybe it's possible to show an info message instead of an outright error and just skip the installation if the system is not a Mac?
When I try to use ttab under my Electron project, it works under dev mode(1), but after building it with electron-packager(2) and executing the binary file, an error appears.
It works with this execution command to debug: # electron .
It fails with this compilation command to package the project: # electron-packager . MyProject --platform=darwin --arch=x64 --version=1.3.5 --overwrite
This is the source code:
var childProcess = require('child_process');
childProcess.execFile(__dirname+'/node_modules/ttab/bin/ttab', ['-w'], function(error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.error('stderr: ' + stderr);
if (error !== null) {
console.error('exec error: ' + error);
}
});
Console displays this error:
stdout:
stderr: 56:62: syntax error: Expected end of line but found “script”. (-2741)
My Env
My node version: v4.5.0
My electron version: v1.3.5
In my experiments, when I Ctrl+C out of long-running commands, it sometimes leaves the tab open, and closes it other times, apparently depending on the program. I'm not sure what's the intended default here, but this seems like behavior I'd want to set per tab anyway. Any way to add a flag for this?
Thanks for this project, @mklement0! However, I find it a bit annoying that I have to use npm to install it, when it's just a simple bash script. Have you considered putting it into Homebrew, as well?
I made a pull request to add this project to Homebrew, but one of the maintainers suggested that this project isn't popular/notable enough to put in the core tap. However, anyone can create their own tap, and I feel like it makes the most sense for the tap for this project to be on your GitHub account, if you're OK with that.
Would you like to create a Homebrew tap, copy my formula file into it, and mention it on the README for this project?
Hey there,
Say I have the following command in my package.json scripts:
"sayHello": "ttab echo hello",
And I run npm run sayHello
from the vscode integrated terminal. Is there a way to have it so that the new terminal that is created is created within the integrated terminal instead of from (in my case) the default mac terminal application?
Thanks very much!
Thomas
The tabs open but doesn't run thecommand
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.