[clug] Terminal Control Sequences

Alex Satrapa grail at goldweb.com.au
Sun Jul 4 19:40:54 MDT 2010


On 05/07/2010, at 00:53 , moncojhr wrote:

> Thanks for the input, so for instance with this:
> 
> echo -e '\033]2;Hello\007'
> 
> which is ESC ] 2 ; Hello BEL
> 
> Am I able to actually type this in?

I have this function defined in my collection of ZSH scripts:

function settitle
{
        print -Pn "\e]0;$1\a"
        return 0
}

Now that I have the function, I can simply do:

 settitle "%n@%m: %~"

in order to have my terminal titles set to eg:

 "alex at Host: ~/Documents"

In ZSH I can run this too:
  preexec () { settitle "%n@%m: %5(~:%-1~/.../%3~:%~) - $1" }
  precmd ()  { settitle "%n@%m: %5(~:%-1~/.../%3~:%~)"      }

… which lets me pick the terminal window I'm after from the drop-down list of window names:

 alex at Host: ~/zsh.d - less S01_Fancy_Prompts
 root at asterisk: /etc/asterisk - vi sip.conf
 foo at was.here: /home/.../bar/baz/tribble

Sadly I haven't had the time/motivation to make the same thing work for Bash or other shells.

So this isn't all related to your question about terminal control codes, so I'll just go back to my recommendation of creating a function for doing each of the funky things you're interested in doing. Then you don't have to worry about Ctrl+V to get verbatim control codes into your shell command, escaping escape codes in "echo" commands, being careful about magic characters, etc. Get it done right once, never fret about it again.

Alex



More information about the linux mailing list