Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash command to change title of screen window (inside the screen session)

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.

like image 519
grill05 Avatar asked Oct 24 '25 11:10

grill05


1 Answers

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.

like image 193
Rajnesh Avatar answered Oct 27 '25 07:10

Rajnesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!