On 20.04.2021 15:30, Spiros Bousbouras wrote:
> On Tue, 20 Apr 2021 13:08:27 +0200
> Janis Papanagnou <
janis_pa...@hotmail.com> wrote:
>> On 20.04.2021 07:18, Kenny McCormack wrote:
>>> In article <s5la58$2ok$
1...@news-1.m-online.net>,
>>> Janis Papanagnou <
janis_pa...@hotmail.com> wrote:
>>>> With the standard shell terminal that I use on Ubuntu I can set the
>>>> window title. E.g. by using the GUI menu (Terminal-> Set Title...),
>>>> or by setting it with a shell command, e.g. with something like
>>>>
>>>> echo -ne "\033]0;SOME TITLE HERE\007"
>>>>
>>>> Is there an equally simple way to _interrogate_ the window title by
>>>> a shell command?
>
> I haven't used Gnome in many years. When I did , there was a gnome-terminal
> application. Is this what you mean by "standard shell terminal" ? The term
> "standard shell terminal" itself is unclear.
Sorry for having been unclear. It's the default thing that comes up
when clicking "Terminal" in the context menu of the screen. It's just
a shell window with a menu, where the 'Help' section mentions that it
is a "GNOME terminal" and "A terminal emulator for the GNOME desktop".
> There may be a standard Gnome
> terminal emulator (gnome-terminal ?) and it may be that the default behaviour
> when you start it is to run a shell but the two are unrelated. Generally
> terminal emulators have a command line option (for example -e in xterm) to
> launch a different executable instead of a shell. [...]
I know that but that seems to not be what I'm looking for but something
completely different.
>
>>> Thinking about this some more, I suppose what you could do is:
>>>
>>> # At the beginning...
>>> echo -ne "\033]0;SOME TITLE HERE\007"
>>> myWinId=$(xdotool search --only --sync --name "SOME TITLE HERE")
>>
>> The problem with this (and also with Richard's suggestion) is that it
>> is not guaranteed that the title is set by command line. It could also
>> be set by the GUI menu and should then also be retrievable.
>
> If you typically open 20-60 shells (and I assume also terminal emulators)
> then surely you should have an automated way of doing it instead of doing it
> by hand.
What do you mean by "it"?
There's no automatism for choosing an appropriate title. Setting the
title, OTOH, is scripted, as is (now) re-setting the title on restart.
>>
>> I have the habit to open an own shell window for every (let's call it)
>> "task domain", and that may easily result in 20-60 shell instances.
>> Such "task domains" may handle topics like "Webpage generation and
>> publishing", "Image processing", "System programming", "Scripting
>> tests", "Book translation", "Doing statistics", "Playing roguelikes",
>> etc. Every domain shall have its own command history (not polluting
>> the other domain's shells), and it shall also memorize the working
>> directory (to have the commands from the history work properly) and
>> window title (to quickly find the right window in the set of minimized
>> windows) persistently in case of reboots (or crashes). Distinguished
>> by the tty/pts number I maintain a couple of dot files (.sh_history_#,
>> .sh_pwdstat_#, .sh_title_#) to restore that information when the shell
>> instances are opened anew.
>
> I take it # refers to "tty/pts number".
Yes.
> If yes , I find it a strange
> choice. If you open a shell for say "System programming" , you terminate it
> and then open a new shell for the same purpose , don't you want the history
> of the 2nd shell to be eventually appended to the history created by the
> earlier shell for "System programming" ? In other words , don't you want files
> .sh_history_* , .sh_pwdstat_* , .sh_title_* to be per task domain rather than
> per tty/pts number ?
We might have a misunderstanding. The point is; the "task domains" are
characterized by doing the same sets of commands. "System programming"
might invoke 'vi', 'cc', 'grep', or 'dmesg', etc. The history file will
memorize these commands. Reopening that shell instance after restarting
the system will work on the same history file and append to it. The CWD
and title, OTOH, will contain the most recent current working directory
and window title, respectively.
If you mean that the files, say, ".sh_history_4", should rather better
be named ".sh_history_System programming", then you won't load that file
automatically, because a restarted /dev/pts/4 doesn't know what task it
is supposed for. I need some automatically generated key (like "4") to
associate the context sets (CWD, title, history). You could of course
do a mapping from "/dev/pts/4" to "System programming", but then you
have no advantage of a verbose file name instead of just using the key.
But I may have misunderstood your suggestion, so please feel free to
explain.
>
> Perhaps I'm misunderstanding what you're trying to do but personally I would
> do something like this :
>
> start_task_specific_shell () {
> # Takes one argument which will be the name of the task
I start a shell window (without arguments) using the GUI context menu.
(Or start a console shell in case of non-windowing low-level access.)
> export TASK_NAME="$1"
> export HISTFILE="$HOME/tasks/.sh_history_$1"
And things like these are done im my $HOME/.kshrc file.
>
> # Issue the command to start the terminal emulator with a window name of $1
> # or something derived from $1 ; for example for xterm
>
> xterm -title "$1" -e /path/to/your/shell
>
> # You probably need to pass some option to the shell so that first it reads
> # $HOME/tasks/.sh_pwdstat_$1 and changes to the directory stored in there.
> }
>
> This way each shell can interrogate the TASK_NAME environmental variable to
> find out what actions it should do on termination and won't have a need to
> learn the window title.
Frankly, I see no advantage doing it that way. As I understand it, since
you pass the "task domain" name as argument, it's easy to "interrogate"
that title, but that is the part where there's also another solution
('xdotool') available.
Is there probably just more than one way to skin a cat, or am I missing
something essential?
Janis