1

set-title ??

I just discover some trick that I use to change a bash-terminal title on the terminal. Here how it works :

#function set-title() on terminal

function set-title() {
  if [[ -z "$ORIG" ]]; then
  ORIG=$PS1
  fi
  TITLE="\[\e]2;$*\a\]"
PS1=${ORIG}${TITLE}
}

I write that code in ~/.bashrc. So I can change the title, and I not confused what terminal I use for.

PRE PROBLEM

I want to customize bash vim and their friend with the new look so I use this guy guide to install powerline and it works perfectly.

PROBLEM

My set title function isn't working now.

WHAT I TRY

Make set-title code to the top of .bashrc not work. (I know this way is stupid)

Write that set-title on usr/share/powerline/bindings/bash/powerline.sh not work, i think the code is different from .bashrc

So how to get my set-title function back?

1
  • how set title work? I just write set-title <your-title-here> and the title text change Apr 1 '18 at 16:22
1

Your method ("\[\e]2;$*\a\]") (outputs Esc];Your title^G(Bel)). This is a "VT100 ESCape sequence" and is not correctly handled by ALL terminal emulators. Compare echo $TERM in both environments.

For a more portable approach, install and use xttitle - Changes X terminal emulator window titles. I have it built into my ~/.bashrc (the cd command adjusts title):

# from the "xttitle(1)" man page - put info in window title
update_title()
{
    [[ $TERM = xterm ]] || [[ $TERM = xterm-color ]]  && xttitle "[$$] ${USER}@${HOSTNAME}:$PWD"
}

cd()
{
    [[ -z "$*" ]] && builtin cd $HOME
    [[ -n "$*" ]] && builtin cd "$*"
    update_title
}
3
  • So i should install the xttitle and write that code on .bashrc ? Ill try that. Apr 1 '18 at 22:55
  • Thanks thats work for me, if I may Ask again what :$PWD use for? Apr 2 '18 at 7:34
  • You may NOT ask a 2nd question. Users searching for "set-title function in bash not work after applying powerline" wouldn't find a $PWD answer, and would not be helped.
    – waltinator
    Apr 2 '18 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.