How can I identify the current terminal emulator f

2019-04-29 12:30发布

问题:

I've got a script that will open a new tab in the OS X Terminal application and I'm trying to add support for iTerm2. Unfortunately, the methods to open tabs in the two terminal emulators are different.

How could I tell which of the two is being used, or is open, to conditionally run the correct script?

回答1:

I'm not sure how to tell iTerm and iTerm2 apart, but check the $TERM_PROGRAM envar. For me (Mac OS X 10.7), it returns Apple_Terminal for Terminal.app, and iTerm.app for iTerm2.



回答2:

You should be able to:

ps -p $$ | tail -1 | awk '{print $NF}'


回答3:

I realize this sounds sarcastic, though why didn't they title the function of "x-terminal-emulator" variably "fly-little-birdy"?

I use Linux. Once I perform a "x-terminal-emulator" function call within bash, that terminal is gone & inaccessible to my scripts.

My point is, bash needs more features for full functionality & utility. A feature of "x-terminal-emulator -attach-to-pid=TERMINAL_NAME" would be alright.

I think it's an oversight in functionality & utility. They could "fix it". :/