Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Setting the terminal title: problem with percent signs
- X-seq: zsh-users 15296
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Guillaume Brunerie <guillaume.brunerie@xxxxxxxxx>
- Subject: Re: Setting the terminal title: problem with percent signs
- Date: Thu, 19 Aug 2010 17:05:49 +0200
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=KfF2Yr7fTzbnpatnSc6HpzOW8rLd4HRjW+IZUcLV2iY=; b=x/OPcxXb9+sjR11srN6gBei5zufO49S4jxIUSHzK1+yuX6vJvDX7mM1LlyWO9B7G6y AiybGafcdStKEo+PWZfBMZTOf1aUajsY+yt7EZtkAaEFNSlKLoAbXx6Sb3tKh9ZzDdgB L7O1969x7PnWooFVHkk24NYW/ljGqY1jk0/Ds=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=v2CQA4h7opWWR5vET1/he69G6R1vAQB/2f1zpOGrq4ANzyJC2jAR1M+68s8J3Z6prn zPpEzp0tF3pDqHSTn5vXQcdsjcOKWPH2TyusGVcbPuW1zKJYsAUrTB4c0HSkWzfvwbEg ZHLbj60UQVzkgIgO4lo3gkTc89uEOx7OgwYYQ=
- In-reply-to: <AANLkTi=oV2M1sQsc8WTPE76rebx6YEbRXs8RE-tOUf5D@xxxxxxxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <AANLkTi=oV2M1sQsc8WTPE76rebx6YEbRXs8RE-tOUf5D@xxxxxxxxxxxxxx>
On 19 August 2010 16:26, Guillaume Brunerie
<guillaume.brunerie@xxxxxxxxx> wrote:
> Hi,
>
> I have the following in my .zshrc which set the terminal title to "*cmd"
> when cmd is executed and to "(cmd)" when execution of cmd is over.
>
> __last_cmd=
> preexec () {
> __last_cmd=$1
> print -Pn "\e]0;*$__last_cmd\a"
> }
> precmd () {
> if [[ -n $__last_cmd ]]
> then
> print -Pn "\e]0;($__last_cmd)\a"
> fi
> }
>
>
> (print -Pn "\e]0;$str\a" change the terminal title to $str, see 'man
> console_codes')
> It works well, except when there are percent signs in the last command.
> For example if I type "echo 100%", the terminal title becomes "(echo 100)"
> instead of "(echo 100%)" and the string " ]0;*echo 100100%" appears in the
> terminal.
>
> How can I do to make it work even with percent signs in the command?
Don't use -P for print, in fact, don't use print at all, since it will
mess up if you use a \ in the command too. printf '\e]0;%s\a' $str
should work better, it won't expand anything in $str at all. If you
have literal escape characters in your command it will still mess up,
you can use ${(V)str} in that case.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author