سؤال

In a gnome-terminal (bash) I can run this command to change the title of the terminal to "hello":

PROMPT_COMMAND='echo -ne "\033]0;hello\007"'

That's great, but now I want to create an alias named "title" in ~/.bashrc to run that command so that I can open any terminal and just type "title" and have the terminal window's name change to "hello".

What is the code that will create the alias so that it works? I'm sure it's a maze of character escape sequences.

Extra bonus points if you can code it so that I can type in something like "title My Window" and the alias will then title the current gnome-terminal to "My Window".

هل كانت مفيدة؟

المحلول 2

that other guy's answer helped. The final solution that worked was adding the following code to .bashrc

function title(){
    PROMPT_COMMAND='echo -ne "\033]0;'"$1"' '"$2"' '"$3"'\007"'
}
export -f title

نصائح أخرى

The rule of thumb about aliases is that if you have to ask, you should use a function instead:

title() {
  printf "\033]2;%s\007" "$*"
}
title "This is my title"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top