How can I identify the current terminal emulator from a bash script?

ぐ巨炮叔叔 提交于 2019-12-07 02:46:51

问题


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". :/



来源:https://stackoverflow.com/questions/7052683/how-can-i-identify-the-current-terminal-emulator-from-a-bash-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!