1

If I check in screen the the currently running tasks (ctrl/a + "), I get this:

 Num Name 0 -bash 1 -bash 2 -bash 

...which is right, normally in my all screen windows, a bash is running. However, not that is what I want to see. I want to see the actually executed command in that window. It can be anything, like ssh-ing, rsync-ing, or running buildscripts and so on:

 Num Name 0 ssh to@this 1 rsync this./ [email protected]:/path 2 make world 

My current best idea, any time if I execute a new command, bash should somehow talk to the screen process, what is happening at the moment. For example, as a datagram message over a unix pipe. Probably it is not easily possible.

Is there something to get at least some similar?

1 Answer 1

3

Short answer:

  • Add the following lines to your $HOME/.bashrc4

    case "$TERM" in screen*) PROMPT_COMMAND='printf "\ek\e\\\\"' esac 
  • Add the following line in $HOME/.screenrc

    shelltitle '$ | bash' 

Explanation:

screen has a shell-specific heuristic that is enabled by setting the window’s name to "<search pattern>|<window name>" and <ESC>k<ESC>\ sequence as part of prompt2.

Screen will use the <ESC>k<ESC>\ to clear the previous command name and get ready for the next command. When a newline is received from the shell, a search is made for the end of the prompt. screen will grab the first word after the matched string and use it as the command name.

Use PROMPT_COMMAND='printf "\ek\e\\\\"' to set <ESC>k<ESC>\ as part of prompt. And use shelltitle subcommand (title does not work here) to set default window title, by adding

shelltitle '<end of prompt>|<default window name>' 

to $HOME/.screenrc2 5.

After loading new configurations windowlist should show command being run.


2. screen dynamic titles: https://www.gnu.org/software/screen/manual/html_node/Dynamic-Titles.html#Dynamic-Titles
4. Similar post: https://superuser.com/questions/244299/gnu-screen-how-to-update-dynamically-the-title-of-a-window
5. shelltitle examples: https://www.gnu.org/software/screen/manual/html_node/Title-Screenrc.html
extra:
3. About PROMPT_COMMAND: https://www.gnu.org/software/bash/manual/html_node/Controlling-the-Prompt.html

7
  • Hi, I tried it and nothing changed. Commented Nov 14, 2023 at 18:02
  • Ref (1) says the same what does not work. Ref(2) is meaningless, probably only the doc author knows what is he writing about. Ref(3) explains PROMPT_COMMAND but not, how to change the window title to the current command. Ref(4) is the origin of your post. Commented Nov 14, 2023 at 18:09
  • I am sorry but your answer is useless in its current form. Commented Nov 14, 2023 at 18:19
  • I was using my custom .screenrc so I didn't realize the answer was incomplete. I apologize. Commented Nov 15, 2023 at 4:48
  • Looks we can't really understand each other. To the .screenrc, you can give a fix string. I want a dynamic string, namely always the currently executing shell command. Did you read the question, at the top of the page? Commented Nov 15, 2023 at 17:04

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.