Identify whether terminal is open in guake

The name of the pictureThe name of the pictureThe name of the pictureClash 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...










share|improve this question





















  • 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














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...










share|improve this question





















  • 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












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...










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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










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





share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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





    share|improve this answer


























      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





      share|improve this answer
























        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





        share|improve this answer














        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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 11 mins ago









        Saurav Shekhar

        31




        31










        answered Nov 29 '14 at 22:43









        Gilles

        514k12110231550




        514k12110231550



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)