2

Can one detect what terminal application is being used? I want the actual application, not TERM env in the question.

I'd like to detect iTerm 2 / Terminal.app so I could set OSX specific keyboard mappings, otherwise PC.

(See ALT+arrow moving between words in zsh and iTerm2 )

Mikko Ohtamaa
  • 2,320
  • 4
  • 27
  • 36
  • You could see if the application is "running" with "ps -ax | grep iTerm" But I am not exactly sure how you would see if it was being "used" – jds May 23 '12 at 15:43

2 Answers2

1

You need to SSH forward local environment variables, as explained here:

http://groups.google.com/group/iterm2-discuss/msg/7cc214c487d31bc8

Mikko Ohtamaa
  • 2,320
  • 4
  • 27
  • 36
-1

I made the following script:

#!/bin/bash

pid=$$ # Current PID
ps -f $$ | head -n 1 # Show the header of ps
while [ $pid -gt 0 ]; do # No more parent when we reach 0 (the kernel)
        ps -f $pid | tail -n +2 # ps current pid and remove header
        pid=$(ps -o ppid $pid|tail -n 1) # Get parent pid
done

It takes the current PID ($$ in bash) and recursively gets the parent PID until we reach 0 (which is the kernel), printing the ps -f output along the way (and a header to start, with ps -f | head -n 1)

Two limitations I can think of:

  1. If run over SSH, the parent will be sshd and not the graphical terminal application.
  2. If executed in a separate script it will print that script too.

However you should be able to grep its output and detect if one of the parent process is iTerm.app or Terminal.app when run locally.

Calimo
  • 1,385
  • 13
  • 18