[olug] Unix Tip: PROGRESS STATUS IN XTERM TITLEBAR

William E. Kempf wekempf at cox.net
Tue Jul 1 21:10:18 UTC 2003


Unix Guru Universe said:
> PROGRESS STATUS IN XTERM TITLEBAR
>
> Sometimes it is handy to be able
> to show some information in the
> xterms title bar, for example
> if you download a set of large
> files (thereby producing lots
> of meaningless information on
> the terminal) and you want to
> know which file is actually
> beeing downloaded.
>
> For this purpose, I hacked a few
> lines of shell code that would
> put any information into the
> xterms title bar. I called the
> script ttshow.
>
> #!/bin/sh
> if [ -z $DISPLAY ]; then
>         echo "ESC]0; $* ^G"
> fi

I use this function, which makes the title a little more permanent.

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}"
}

> In this little script, the
> string ESC has to be replaced
> by one real escape character
> (ascii 0x1b), the string "^G"
> has to be replaced by a bel
> character (ascii 0x07).

Which can be done with out placing literal characters in the string, by
using "echo -e".  Read the man page on echo for escape sequences permitted
by this.

-- 
William E. Kempf




More information about the OLUG mailing list