screen-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get current window title in bash


From: Neal Fultz
Subject: Re: Get current window title in bash
Date: Wed, 9 Feb 2022 09:20:53 -0800

I took a try at this, but didn't find any ideal solution.

Usually people set the window title from bash's prompt command, not the other way around.

There is an xterm escape code for "reporting a window title" that screen appears to support. There's a SO post that implies that it's usually disabled for security reasons.

The result comes back wrapped in escapes as well. 

Here's as far as I got:

nfultz@penguin:~$ read -p '^[[21t' -rs -d '\' A < $(tty)
nfultz@penguin:~$ echo ${A//[^[:alnum:] ]/}
lbash

Probably the best thing to do is write a small C program and use it...

Best,

Neal



On Wed, Feb 9, 2022 at 7:21 AM Иванов Дмитрий <d.ivanov@1001tur.ru> wrote:
My goal is to print the current window title in bash prompt. Currently I
know $WINDOW environment variable that contains the number of the
currently selected window.

I learned about "screen -Q title" command but 2 problems emerged:

1. This command is slow and makes a delay when used in .bashrc.
2. When I tried this code:

if [ -n "$STY" ]; then
     TITLE=$(screen -Q title)
     PS1=$PS1"\[\033[01;93m\]$TITLE "
fi

It shows the title in the prompt and I have to click extra Enter key. Is
it possible to get the name quickly?


reply via email to

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