[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Detecting shell type (ie: is/non interactive/ssh/login s
From: |
Assaf Gordon |
Subject: |
Re: [Help-bash] Detecting shell type (ie: is/non interactive/ssh/login shell) |
Date: |
Fri, 9 Sep 2016 21:13:00 -0400 |
Hello Matthew,
> On Sep 9, 2016, at 18:22, Bob Proulx <address@hidden> wrote:
>
> Matthew Giassa wrote:
>> [...] to provide some additional UX features depending on what type of
>> shell is currently being used. IE: when in interactive mode, a green
>> light icon is illuminated; while running a script or lengthy command via
>> "bash -c" an amber light icon is lit; if a remote session is launched in
>> a special manner, other features kick in, etc.
> [...]
> However if you are really wanting to know in a script if it is
> interactive or not a typical way is to look to see if stdin is
> connected to a tty device or not.
Perhaps this is a bit of an xy-problem:
Instead of just asking if the shell is interactive or not, you likely want to
know if the current session (inside your guake/konsole) is "busy" or not, i.e.
what is running in the foreground.
I would suggest investigating an existing program that already tries to do such
thing: tmux .
tmux ( the screen multiplexer https://tmux.github.io ) has code to detect what
is the 'active' program in the current session by checking the process
associated with the either current TTY or querying the foreground process in a
process group associated with a terminal (like Bob said).
It then displays the program name in the task bar - it's not perfect, but it
works well most of the time. And they already wrote all the code to do it for
multiple operating systems.
See the function 'osdep_get_name', which is implemented differently for each
system, e.g for linux:
https://github.com/tmux/tmux/blob/5658b628b9bf1c1e0bd5856736332ce8b9c51517/osdep-linux.c#L30
and the way it is used here:
https://github.com/tmux/tmux/blob/05ec232f3ec567351405f276693735056156527d/format.c#L394
I know nothing about guake/konsole, but I would naively guess that you can
know what is the shell process you've started inside it, and if it's not the
'active' one in the foreground, the console session is 'busy' (likely there
will be many possible complications in practice, but still....).
HTH,
-assaf