* Setting the terminal title: problem with percent signs
@ 2010-08-19 14:26 Guillaume Brunerie
2010-08-19 15:05 ` Mikael Magnusson
2010-09-01 13:14 ` Antwort: " stefan.albert
0 siblings, 2 replies; 4+ messages in thread
From: Guillaume Brunerie @ 2010-08-19 14:26 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 747 bytes --]
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?
Thank you
Guillaume Brunerie
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Setting the terminal title: problem with percent signs
2010-08-19 14:26 Setting the terminal title: problem with percent signs Guillaume Brunerie
@ 2010-08-19 15:05 ` Mikael Magnusson
2010-08-19 15:19 ` Guillaume Brunerie
2010-09-01 13:14 ` Antwort: " stefan.albert
1 sibling, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2010-08-19 15:05 UTC (permalink / raw)
To: Guillaume Brunerie; +Cc: zsh-users
On 19 August 2010 16:26, Guillaume Brunerie
<guillaume.brunerie@gmail.com> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Setting the terminal title: problem with percent signs
2010-08-19 15:05 ` Mikael Magnusson
@ 2010-08-19 15:19 ` Guillaume Brunerie
0 siblings, 0 replies; 4+ messages in thread
From: Guillaume Brunerie @ 2010-08-19 15:19 UTC (permalink / raw)
To: Mikael Magnusson; +Cc: zsh-users
[-- Attachment #1: Type: text/plain, Size: 1472 bytes --]
2010/8/19 Mikael Magnusson <mikachu@gmail.com>
> On 19 August 2010 16:26, Guillaume Brunerie
> <guillaume.brunerie@gmail.com> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Antwort: Setting the terminal title: problem with percent signs
2010-08-19 14:26 Setting the terminal title: problem with percent signs Guillaume Brunerie
2010-08-19 15:05 ` Mikael Magnusson
@ 2010-09-01 13:14 ` stefan.albert
1 sibling, 0 replies; 4+ messages in thread
From: stefan.albert @ 2010-09-01 13:14 UTC (permalink / raw)
To: Guillaume Brunerie, zsh-users
[-- Attachment #1: Type: text/plain, Size: 1108 bytes --]
Hi,
you have to substitute the % with %%
Change the line : __last_cmd=$1
in something like that: __last_cmd=`echo $1 | sed -e "s/%/%%/g"`
this should do the job.
Stefan
Von: Guillaume Brunerie <guillaume.brunerie@gmail.com>
An: zsh-users@zsh.org
Datum: 19.08.2010 16:51
Betreff: Setting the terminal title: problem with percent signs
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?
Thank you
Guillaume Brunerie
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-09-01 13:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-19 14:26 Setting the terminal title: problem with percent signs Guillaume Brunerie
2010-08-19 15:05 ` Mikael Magnusson
2010-08-19 15:19 ` Guillaume Brunerie
2010-09-01 13:14 ` Antwort: " stefan.albert
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).