From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6013 invoked by alias); 19 Aug 2010 15:19:40 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 15297 Received: (qmail 18062 invoked from network); 19 Aug 2010 15:19:38 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 74.125.83.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:cc:content-type; bh=e1kHaHH4iju0W6ow8M8ZSaMOOtDc2wti3YrM/jBeWAo=; b=RMmUuDlFIDmtSM2Jg1Df/3qAYhbLIkQYmIb6oGYdsgZXtu1TwQ7CLyxIsisS0avGXu GqYRb8g4qKQ9/D/X02HBsvICNdY6ip6Wz2BGhPQRLyD/AVf4gJ+5oJd3Ep3neeSSo38g TQjnlMYk9ovmjqMwlE/zXm14Le7zaESZ3ltbo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=J8jUOK3hAb4EL4WRrBiop591DZ6kCmQqNfHuUH5ssbj6rBQUjv4MEKZpj3wjMVXvaS afd58LOAvTpBZj8k0ZwqDlroJ4aHBvMbN+BcKT9DoNNP05tdlNcb+hGVCz5NQN2Csa4N mPQes8tDmcqmDvjUwQ7ce2AOrlRw3aOIASIjs= MIME-Version: 1.0 In-Reply-To: References: From: Guillaume Brunerie Date: Thu, 19 Aug 2010 17:19:19 +0200 Message-ID: Subject: Re: Setting the terminal title: problem with percent signs To: Mikael Magnusson Cc: zsh-users@zsh.org Content-Type: multipart/alternative; boundary=0016e64715d0b0fe25048e2eb588 --0016e64715d0b0fe25048e2eb588 Content-Type: text/plain; charset=UTF-8 2010/8/19 Mikael Magnusson > On 19 August 2010 16:26, Guillaume Brunerie > 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 > Yes, I don't know why I had the -P option for print but after reading the man page it was indeed stupid. It works very good with printf, thank you :-) Guillaume Brunerie --0016e64715d0b0fe25048e2eb588--