Moved this question here from StackOverflow

I use KeePass as my password manager and I heavily utilize it's auto-type feauture. Since the auto-type function only looks at the window title to filter for the password entries it works best with window titles as distinct as possible.

Now when I'm logged into one of my servers via PuTTY I have the window title usually configured to some fixed string like the hostname or so. When executing a command which prompts me for a password (e.g. sudo or mysql) I normally hit the hotkey for auto-type and it brings up the Keepass window with all the found entries for that particular window filtered by the title. Unfortunatelly that list contains all the entries for a particular host since I'm managing all sorts of user accounts and passwords linked to that host in KeePass.

Say I want to log into MySQL with user <root> and my PuTTY window title is set to <PuTTY - myhost.name>. When I hit the auto-type hotkey KeePass brings up all the entries associated with that window title and I have to navigate first through that list to find the right entry. So I was thinking of setting PuTTY's window title to something like <PuTTY - myhost.name : MySQL password for user 'root'> from within Linux when executing the mysql command so I could apply a regex filter like //PuTTY.*myhost\.name.*MySQL.*'root'// to my password entry in KeePass and it would just find that particular entry and auto-type it for me right away. After the command was fired (mysql accepted the password and offers me the MySQL command prompt) I'd like to reset the window title to what it was before.

Is this possible somehow and if so, what would be the cleanest way of doing so?

Hope I made my problem clear. Any help is highly appreciated!

1 Answer 1


See Display command in xterm titlebar

trap 'printf "\033]0;%s\007" "${BASH_COMMAND//[^[:print:]]/}"' DEBUG

Older answer:

You should be able to create an alias or shell-script for mysql that executes the commands to

  • set the window title as you want
  • run your app (e.g. mysql)
  • set the window title back to something else

You can set the window title using something like

  echo -e "\e]0;running mysql\a"
  echo -e "\e]0;running bash\a"

where -e causes bash to interpret "\e" as the ASCII control-character ESC (Escape 0x0b) and "\a" as the ASCII control-character alert or BEL (Bell 0x07)

ESC is a command sequence introducer (CSI) and ESC followed by ]0; is a so-called Escape-sequence that is used to perform some control action in a terminal.

If this doesn't seem to work, put the following in a script file

  echo -e "\e]0;desired-title\a"
  sleep 5s

Then run it, if the title changes to "desired-title" for 5 seconds then something else is overriding your window title. You'll have to track that down and disable it.

See also

  • This doesn't work for me on ubuntu 18.04 even after a reboot of the server
    – Freedo
    Sep 14, 2020 at 6:08
  • @Freedo, you never need to reboot a Linux server for anything like this (or, in general for anything except a major reinstall or hardware upgrade). See amended answer. I may add more later. Sep 14, 2020 at 9:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .