Setting Konsole title to $USER@$HOSTNAME

First: Settings -> Configure Konsole -> General -> Show window title on the titlebar (checked)

Then: System -> Configure Konsole -> Profiles -> [Default] -> Edit… -> Tabs:

  • Tab title format: %w
  • Remote table title format: %w

Then you need this config and these two shell functions in your .bashrc:

# 2023-12-29 jj5 - if not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# 2023-12-29 jj5 - set the Konsole window title
echo -ne "\033]2;$USER@$HOSTNAME\007" >&2

# 2023-12-29 jj5 - intercept ssh and sudo commands to reset window title on exit:
ssh() {
    /usr/bin/ssh "$@"
    echo -ne "\033]2;$USER@$HOSTNAME\007" >&2
}
sudo() {
    /usr/bin/sudo "$@"
    echo -ne "\033]2;$USER@$HOSTNAME\007" >&2
}