[arch-general] Dynamic Titles in urxvt (bash) Without Side Effects?

Tobias Frilling tobias at frilling-online.de
Wed Nov 16 09:17:13 EST 2011


On 11/16/2011 02:51 PM, Bastien Dejean wrote:
> Hey,
> 
> I've added the following lines to my .bashrc:
> 
>     case "$TERM" in
>         rxvt*|xterm*)
>             set -o functrace
>             trap '[ -z "$BASH_SOURCE" ] && printf "%b" "\e]0;$BASH_COMMAND\a"' DEBUG >& /dev/null
>             ;;
>     esac
> 
> (It sets the current title of the current window according to the last
> ran command.)
> 
> But alas, it generates side effects, if I issue this:
> 
>     ls "$(ls -1 | head -1)"
> 
> I get:
> 
>     ls: cannot access foo.bar: No such file or directory
> 
> Strange or trivial?
> 
> Cheers,

I don't know much about parameter modifiers in bash, but in zsh this
works for me:

title () {
	1=${(%)1}
	1=${(V)1}
	1=${(q)1}

	case $TERM in
		screen*)
			print -n "\ek$1\e\\" ;;
		linux)
			;;
		*)
			print -n "\e]2;$1\a" ;;
	esac
}

The (%) modifier expands % escapes like in a prompt expansion (so %~
becomes the directory), (V) makes any special characters in the
resulting words visible (so a newline becomes \n) and the (q) modifier
quotes special characters with backslashes.

Don't know if this may help you.



More information about the arch-general mailing list