문제

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