help-bash
[Top][All Lists]
Advanced

[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: Matthew Giassa
Subject: Re: [Help-bash] Detecting shell type (ie: is/non interactive/ssh/login shell)
Date: Sat, 10 Sep 2016 21:27:28 -0700
User-agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

Hi Assaf,

As it stands, I can state this is not an XY problem. The information provided is the exactly desired behavior. Knowing these values for the sake of knowing them is goal. The goal is not to know whether or not the system is busy.


On 09/09/16 18:13, Assaf Gordon wrote:
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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]