* truncating string in .zprofile
@ 2013-03-20 18:28 Eric Smith
2013-03-20 19:41 ` Paul Hoffman
0 siblings, 1 reply; 6+ messages in thread
From: Eric Smith @ 2013-03-20 18:28 UTC (permalink / raw)
To: Zsh Users
I have the following prexec() in my profile;
preexec () { print -Pn "\033k\033\134\033k[$1]\033\134" }
This prints the command in the screen caption for that window.
What I want to do is limit this window title to n chars.
However, I cannot manipulate the `$1' in the print string.
Even if I try.
substring=$1
preexec () { print -Pn "\033k\033\134\033k[$substring]\033\134" }
then there is no value printed for $substring.
What is the solution?
Thank
Eric Smith
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: truncating string in .zprofile
2013-03-20 18:28 truncating string in .zprofile Eric Smith
@ 2013-03-20 19:41 ` Paul Hoffman
2013-03-20 20:17 ` Eric Smith
0 siblings, 1 reply; 6+ messages in thread
From: Paul Hoffman @ 2013-03-20 19:41 UTC (permalink / raw)
To: zsh-users
On Wed, Mar 20, 2013 at 07:28:27PM +0100, Eric Smith wrote:
> I have the following prexec() in my profile;
> preexec () { print -Pn "\033k\033\134\033k[$1]\033\134" }
>
> This prints the command in the screen caption for that window.
>
> What I want to do is limit this window title to n chars.
>
> However, I cannot manipulate the `$1' in the print string.
> Even if I try.
> substring=$1
> preexec () { print -Pn "\033k\033\134\033k[$substring]\033\134" }
>
> then there is no value printed for $substring.
>
> What is the solution?
preexec() {
print -Pn "\033k\033\134\033k["${1[1,30]}"]\033\134"
}
Paul.
--
Paul Hoffman <nkuitse@nkuitse.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: truncating string in .zprofile
2013-03-20 19:41 ` Paul Hoffman
@ 2013-03-20 20:17 ` Eric Smith
2013-03-20 20:45 ` Paul Hoffman
0 siblings, 1 reply; 6+ messages in thread
From: Eric Smith @ 2013-03-20 20:17 UTC (permalink / raw)
To: zsh-users
> > What is the solution?
>
> preexec() {
> print -Pn "\033k\033\134\033k["${1[1,30]}"]\033\134"
> }
>
Yummy!
Eric
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: truncating string in .zprofile
2013-03-20 20:17 ` Eric Smith
@ 2013-03-20 20:45 ` Paul Hoffman
2013-03-20 20:54 ` Eric Smith
0 siblings, 1 reply; 6+ messages in thread
From: Paul Hoffman @ 2013-03-20 20:45 UTC (permalink / raw)
To: zsh-users
On Wed, Mar 20, 2013 at 09:17:56PM +0100, Eric Smith wrote:
> Yummy!
Correcting myself:
preexec() {
print -Pn "\033k\033\134\033k[${1[1,30]}]\033\134"
}
Paul.
--
Paul Hoffman <nkuitse@nkuitse.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: truncating string in .zprofile
2013-03-20 20:45 ` Paul Hoffman
@ 2013-03-20 20:54 ` Eric Smith
2013-03-21 12:34 ` Paul Hoffman
0 siblings, 1 reply; 6+ messages in thread
From: Eric Smith @ 2013-03-20 20:54 UTC (permalink / raw)
To: zsh-users
--
Best regards,
Eric Smith
Mobile: 00 31 6 455 09313 - Tel Wageningen: +31 317 728888
Paul Hoffman wrote on Wed-20-Mar 13 9:45PM
> On Wed, Mar 20, 2013 at 09:17:56PM +0100, Eric Smith wrote:
> > Yummy!
>
> Correcting myself:
>
> preexec() {
> print -Pn "\033k\033\134\033k[${1[1,30]}]\033\134"
> }
>
Funny, I did not even register those double quotes, just saw the
extra set of braces and then kicked myself, just like a solution
to many perl issues when you need an extra layer of eval.
I did this -
preexec () { print -Pn
"\033k\033\134\033k[${1[1,12]}..${1[-6,$]}]\033\134" }
How would I do arbitrary string searching and replacement in the `$1'?
Like to grab the top level domain from a URL or whatever.
Currently my window captions look like this:
[s asteri..vvvvv -c] 1 [vim .screenc..aptio] 4 [vim food..2013.txt]
Nice, but still a bit lame.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: truncating string in .zprofile
2013-03-20 20:54 ` Eric Smith
@ 2013-03-21 12:34 ` Paul Hoffman
0 siblings, 0 replies; 6+ messages in thread
From: Paul Hoffman @ 2013-03-21 12:34 UTC (permalink / raw)
To: zsh-users
On Wed, Mar 20, 2013 at 09:54:48PM +0100, Eric Smith wrote:
> I did this -
> preexec () { print -Pn
> "\033k\033\134\033k[${1[1,12]}..${1[-6,$]}]\033\134" }
>
> How would I do arbitrary string searching and replacement in the `$1'?
Any way you want -- grep, sed, or plain zsh.
preexec() {
print -Pn "\033k\033\134\033k[$(
print -n 'uptime: '
uptime | perl -pe ...
)]\033\134"
}
Paul.
--
Paul Hoffman <nkuitse@nkuitse.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-03-21 13:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-20 18:28 truncating string in .zprofile Eric Smith
2013-03-20 19:41 ` Paul Hoffman
2013-03-20 20:17 ` Eric Smith
2013-03-20 20:45 ` Paul Hoffman
2013-03-20 20:54 ` Eric Smith
2013-03-21 12:34 ` Paul Hoffman
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).