Identify whether terminal is open in guake

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I need to check in my .vimrc whether or not the terminal in which vim is opened is running in Guake. How can I see this? The $TERM variable does not seem to be quite right...
terminal guake
add a comment |Â
up vote
2
down vote
favorite
I need to check in my .vimrc whether or not the terminal in which vim is opened is running in Guake. How can I see this? The $TERM variable does not seem to be quite right...
terminal guake
Exactly what is guake? Is it a process?
â DisplayName
Nov 28 '14 at 13:42
1
@DisplayName Guake is a graphical terminal emulator for GNOME.
â jw013
Nov 28 '14 at 17:16
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I need to check in my .vimrc whether or not the terminal in which vim is opened is running in Guake. How can I see this? The $TERM variable does not seem to be quite right...
terminal guake
I need to check in my .vimrc whether or not the terminal in which vim is opened is running in Guake. How can I see this? The $TERM variable does not seem to be quite right...
terminal guake
terminal guake
asked Nov 28 '14 at 11:23
lindhe
1,26231226
1,26231226
Exactly what is guake? Is it a process?
â DisplayName
Nov 28 '14 at 13:42
1
@DisplayName Guake is a graphical terminal emulator for GNOME.
â jw013
Nov 28 '14 at 17:16
add a comment |Â
Exactly what is guake? Is it a process?
â DisplayName
Nov 28 '14 at 13:42
1
@DisplayName Guake is a graphical terminal emulator for GNOME.
â jw013
Nov 28 '14 at 17:16
Exactly what is guake? Is it a process?
â DisplayName
Nov 28 '14 at 13:42
Exactly what is guake? Is it a process?
â DisplayName
Nov 28 '14 at 13:42
1
1
@DisplayName Guake is a graphical terminal emulator for GNOME.
â jw013
Nov 28 '14 at 17:16
@DisplayName Guake is a graphical terminal emulator for GNOME.
â jw013
Nov 28 '14 at 17:16
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
There is no foolproof way. TERM uses the same value for mostly-compatible emulators; most modern terminal emulators aside from screen and tmux report xterm.
You can explore the process list to find Vim's parent's parent. That will tell you in what terminal emulator (if any) Vim is running in in the common case where Vim was launched from a shell which was started directly in the terminal emulator. You can even be a little smarter and traverse the process list, going from Vim to its parent, then its parent's parent, and so on, and stopping when you find a process that isn't running on the same terminal as its child: that process is probably a terminal emulator.
This heuristic can be fooled in a number of ways âÂÂàin particular because it is possible (though uncommon) to start a program from anywhere and make it interact in another terminal by redirecting its input and output.
Here's a lightly-tested script which shows the command line of the terminal emulator that the current process is running on, assuming that the process is started as a descendant of that terminal emulator with no redirection shenanigans.
#! /bin/sh
set -f
pid=$PPID
my_tty=$(ps -p $$ -o tty=)
while
[ "$pid" -ne 1 ] &&
set -- $(ps -p "$pid" -o ppid= -o tty= -o args=) &&
[ "$2" = "$my_tty" ]
do
pid=$1
done
shift; shift
printf '%sn' "$*"
Call this script which-terminal-emulator. In your .vimrc, you can add
let terminal_emulator=system('which-terminal-emulator')
if terminal_emulator =~ '.*guake.*$'
â¦
endif
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
There is no foolproof way. TERM uses the same value for mostly-compatible emulators; most modern terminal emulators aside from screen and tmux report xterm.
You can explore the process list to find Vim's parent's parent. That will tell you in what terminal emulator (if any) Vim is running in in the common case where Vim was launched from a shell which was started directly in the terminal emulator. You can even be a little smarter and traverse the process list, going from Vim to its parent, then its parent's parent, and so on, and stopping when you find a process that isn't running on the same terminal as its child: that process is probably a terminal emulator.
This heuristic can be fooled in a number of ways âÂÂàin particular because it is possible (though uncommon) to start a program from anywhere and make it interact in another terminal by redirecting its input and output.
Here's a lightly-tested script which shows the command line of the terminal emulator that the current process is running on, assuming that the process is started as a descendant of that terminal emulator with no redirection shenanigans.
#! /bin/sh
set -f
pid=$PPID
my_tty=$(ps -p $$ -o tty=)
while
[ "$pid" -ne 1 ] &&
set -- $(ps -p "$pid" -o ppid= -o tty= -o args=) &&
[ "$2" = "$my_tty" ]
do
pid=$1
done
shift; shift
printf '%sn' "$*"
Call this script which-terminal-emulator. In your .vimrc, you can add
let terminal_emulator=system('which-terminal-emulator')
if terminal_emulator =~ '.*guake.*$'
â¦
endif
add a comment |Â
up vote
2
down vote
accepted
There is no foolproof way. TERM uses the same value for mostly-compatible emulators; most modern terminal emulators aside from screen and tmux report xterm.
You can explore the process list to find Vim's parent's parent. That will tell you in what terminal emulator (if any) Vim is running in in the common case where Vim was launched from a shell which was started directly in the terminal emulator. You can even be a little smarter and traverse the process list, going from Vim to its parent, then its parent's parent, and so on, and stopping when you find a process that isn't running on the same terminal as its child: that process is probably a terminal emulator.
This heuristic can be fooled in a number of ways âÂÂàin particular because it is possible (though uncommon) to start a program from anywhere and make it interact in another terminal by redirecting its input and output.
Here's a lightly-tested script which shows the command line of the terminal emulator that the current process is running on, assuming that the process is started as a descendant of that terminal emulator with no redirection shenanigans.
#! /bin/sh
set -f
pid=$PPID
my_tty=$(ps -p $$ -o tty=)
while
[ "$pid" -ne 1 ] &&
set -- $(ps -p "$pid" -o ppid= -o tty= -o args=) &&
[ "$2" = "$my_tty" ]
do
pid=$1
done
shift; shift
printf '%sn' "$*"
Call this script which-terminal-emulator. In your .vimrc, you can add
let terminal_emulator=system('which-terminal-emulator')
if terminal_emulator =~ '.*guake.*$'
â¦
endif
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
There is no foolproof way. TERM uses the same value for mostly-compatible emulators; most modern terminal emulators aside from screen and tmux report xterm.
You can explore the process list to find Vim's parent's parent. That will tell you in what terminal emulator (if any) Vim is running in in the common case where Vim was launched from a shell which was started directly in the terminal emulator. You can even be a little smarter and traverse the process list, going from Vim to its parent, then its parent's parent, and so on, and stopping when you find a process that isn't running on the same terminal as its child: that process is probably a terminal emulator.
This heuristic can be fooled in a number of ways âÂÂàin particular because it is possible (though uncommon) to start a program from anywhere and make it interact in another terminal by redirecting its input and output.
Here's a lightly-tested script which shows the command line of the terminal emulator that the current process is running on, assuming that the process is started as a descendant of that terminal emulator with no redirection shenanigans.
#! /bin/sh
set -f
pid=$PPID
my_tty=$(ps -p $$ -o tty=)
while
[ "$pid" -ne 1 ] &&
set -- $(ps -p "$pid" -o ppid= -o tty= -o args=) &&
[ "$2" = "$my_tty" ]
do
pid=$1
done
shift; shift
printf '%sn' "$*"
Call this script which-terminal-emulator. In your .vimrc, you can add
let terminal_emulator=system('which-terminal-emulator')
if terminal_emulator =~ '.*guake.*$'
â¦
endif
There is no foolproof way. TERM uses the same value for mostly-compatible emulators; most modern terminal emulators aside from screen and tmux report xterm.
You can explore the process list to find Vim's parent's parent. That will tell you in what terminal emulator (if any) Vim is running in in the common case where Vim was launched from a shell which was started directly in the terminal emulator. You can even be a little smarter and traverse the process list, going from Vim to its parent, then its parent's parent, and so on, and stopping when you find a process that isn't running on the same terminal as its child: that process is probably a terminal emulator.
This heuristic can be fooled in a number of ways âÂÂàin particular because it is possible (though uncommon) to start a program from anywhere and make it interact in another terminal by redirecting its input and output.
Here's a lightly-tested script which shows the command line of the terminal emulator that the current process is running on, assuming that the process is started as a descendant of that terminal emulator with no redirection shenanigans.
#! /bin/sh
set -f
pid=$PPID
my_tty=$(ps -p $$ -o tty=)
while
[ "$pid" -ne 1 ] &&
set -- $(ps -p "$pid" -o ppid= -o tty= -o args=) &&
[ "$2" = "$my_tty" ]
do
pid=$1
done
shift; shift
printf '%sn' "$*"
Call this script which-terminal-emulator. In your .vimrc, you can add
let terminal_emulator=system('which-terminal-emulator')
if terminal_emulator =~ '.*guake.*$'
â¦
endif
edited 11 mins ago
Saurav Shekhar
31
31
answered Nov 29 '14 at 22:43
Gilles
514k12110231550
514k12110231550
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f170428%2fidentify-whether-terminal-is-open-in-guake%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Exactly what is guake? Is it a process?
â DisplayName
Nov 28 '14 at 13:42
1
@DisplayName Guake is a graphical terminal emulator for GNOME.
â jw013
Nov 28 '14 at 17:16