2

I am wanting to know how I can display the TTY a terminal is currently using in the window name of the Terminal. I don't see any options in Terminal Preferences to display such thing on the Terminal window name with gnome-terminal.

I ask this because I was using Terminal on Mac OS X and I could set in the preferences to display what TTY the terminal is currently using, and just wondering how I could do the same for gnome-terminal, and yes I do know that Terminal on both Mac and Linux are completely different, yet they share the same UNIX command line stuff.

Is there something I could add to .bashrc or .profile to append this to the window name of Terminal? or perhaps something I could add to dconf to make this a custom option?

I do know that typing tty is an option or ps -a to display that, but that only displays inside the terminal window output, but in the window name I'd like it to show all the time and for every new window or tab that opens ie; /dev/tty/1, /dev/tty/2, /dev/tty/3 etc… appended to the Window title like these for example.

Terminal | tty/1
Terminal, tty/2

2 Answers2

2

You can modify your .bashrc as follow:

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;$(tty | cut -d/ -f3,4) | ${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

Now new gnome-terminal will look like this:

enter image description here

Note that gnome-terminal uses Pseudo-Terminals, see What does "pts/" in the output of w mean?

0

Set a PROMPT_COMMAND in your ~/.bashrc like so:

PROMPT_COMMAND='echo -ne "\033]0;$(tty | sed s:/dev/::)\007"'

Note that this title may be overwritten by other things, such as your prompt (PS1), so be sure to check at least PS1 if your title is not being set.

Reference:

muru
  • 207,228