This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: changing bash window title


Igor Pechtchanski said:
> On Wed, 18 Jun 2003, Sanjay Goel wrote:
>
>> Igor Pechtchanski wrote:
>> > On Wed, 18 Jun 2003, Sanjay Goel wrote:
>> >
>> >> Hi Igor,
>> >> I added this line in my .bashrc
>> >> function settitle() { echo -n "^[]2;$@^G^[]1;$@^G"; }
>> >> now when I write settitle sanjay on my $ , it does not change my
>> title .. this is what happens
>> >>
>> >> [~]$ settitle sanjay
>> >> ^[]2;sanjay^G^[]1;sanjay^G[~]$
>> >> [~]$
>> >>
>> >> what is it that I am missing ?
>> >> Sanjay
>> >
>> > The control characters.  ^[ is *one* character, Ctrl-[ (aka ESC).
>> ^G is also *one* character, Ctrl-G (aka BEL).  Fix that, and the
>> > incantation should work.
>> > Igor
>>
>> How do I add these control characters in my .bashrc .. I opened the
>> file in vim but pressing Ctrl-[ does not work
>> Sanjay
>
> Yeah, next time I'll go with my first impulse and put that in right
> away. Try Ctrl-V Ctrl-[ (in the vim insert mode).  Same for Ctrl-G.

Why not do away with the fragile binary characters here and instead do:

function settitle() { echo -ne "\e]2;$@\a\e]1;$@\a"; }

Or the simpler:

function settitle() { echo -ne "\e]0;$@\a"; }

I actually use the following, which sets the title via the prompt (which
means it's more persistent):

function settitle()
{
    if [ $# -eq 0 ]
        then
        eval set -- "\\u@\\h: \\w"
    fi

    case $TERM in
        xterm*) local title="\[\033]0;$@\007\]";;
        *) local title=''
    esac
    local prompt=$(echo "$PS1" | sed -e 's/\\\[\\033\]0;.*\\007\\\]//')
    PS1="${title}${prompt}"
}

With this, it's nice to do:

$ PS1="\u\$ "
$ settitle "\\h: \\w"

This puts the user name in the prompt, and the host and working directory
in the title bar.

-- 
William E. Kempf



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]