Reputation: 181
I want to set the title of the current screen window (inside the screen session) via a bash command.
I know it can be done via C-a A, but that does not work directly as a shell command.
screen -t <mytitle> <args>
in the current window works, but it creates a new window. I want to rename the current window.
All the posts I saw either dealt with doing this outside a running screen session, or used the screen keybindings/commands.
Upvotes: 4
Views: 2887
Reputation: 181
I used a variant of R.k. Lohana's answer that uses python.
import os;
if __name__=='__main__':
title=sys.argv[1]
info=r'echo -n "\033k%s\033\\"' %(title)
os.system(info)
Upvotes: 0
Reputation: 923
Open your ~/.bashrc file in gedit
gedit ~/.bashrc
Add the following function at the end of the file.
# function to set terminal title
function settitle(){
if [[ -z "$ORIG" ]]; then
ORIG=$PS1
fi
TITLE="\[\e]2;$*\a\]"
PS1=${ORIG}${TITLE}
}
Rerun the bashrc file to make changes effective in the current terminal. This won't be needed afterwards.
source ~/.bashrc
Now using the function rename the terminal name from the shell. From the shell type
settitle hello
This will name it hello.
Upvotes: 3