Friday, 29 June 2018

debian - How do I choose what shows up in PuTTY title bar from Linux?


In the PuTTY configuration there's an option in Terminal → Features called Disable remote-controlled window title changing. Without that enabled, the title bar of PuTTY will change every time I press return in the console.


I was thinking it'd be a more clean solution to set the title bar text from Linux than to specify one for every PuTTY client I have laying around. So where can I modify what Linux sets as the window title?





$ uname -a
Linux drevo 2.6.32-5-amd64 #1 SMP Mon Jan 16 16:22:28 UTC 2012 x86_64 GNU/Linux

$ cat /etc/debian_version
6.0.4

Answer



Most terminal programs - including konsole, putty and xterm - emulate the old VT100 terminal. This terminal allows you to set certain things, including bold, colors, setting the terminal title, and so on, using special character sequences called escape sequences.


The bash shell has a variable called PROMPT_COMMAND which, if set, is evaluated before every prompt you print out (I believe zsh has something similar, in fact I think bash took the code from them). You can output escape sequences in PROMPT_COMMAND and it will set your title bar.


This is what I have in mine (Linux/bash):


USER=$(/usr/bin/id -un)
HOSTNAME=$(uname -n)
HOSTNAME=${HOSTNAME%%.*}
PROMPT_COMMAND='echo -ne "\e]0;$USER@${HOSTNAME}: $(pwd -P)\a"'

You can put this in your ~/.bashrc


There are a lot of customizations you can do with your terminal. I like bold in my prompt, to make it easier to see the end of my prompt. This makes it bold yellow, good against my default black background:


PS1="\[\e[33;1m\]\h:\$\[\e[0m\] "

Look around for Linux Prompt Customization, you'll find more HowTos than you'll know what to do with. Pick the one that you find easiest to read.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...