Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh tips for "UNIX Power Tools"
- X-seq: zsh-users 2941
- From: Thomas Köhler <jean-luc@xxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxxxxxx
- Subject: Re: zsh tips for "UNIX Power Tools"
- Date: Sat, 4 Mar 2000 13:05:47 +0100
- In-reply-to: <1000304054014.ZM21187@xxxxxxxxxxxxxxxxxxxxxxx>; from schaefer@xxxxxxxxxxxxxxxxxxxxxxx on Sat, Mar 04, 2000 at 06:40:44AM +0100
- Mail-followup-to: Thomas Köhler <jean-luc@xxxxxxxxxxxxxxxxx>, zsh-users@xxxxxxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <28174.952013581@xxxxxxxxx> <20000303123932.A11036@xxxxxxxxxxxxxxxxx> <87k8jjwt6h.fsf@xxxxxxxxxxxxxxxxxxxx> <1000304054014.ZM21187@xxxxxxxxxxxxxxxxxxxxxxx>
On Sat, Mar 04, 2000 at 06:40:44AM +0100,
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Mar 3, 12:39pm, Thomas Köhler wrote:
> } Subject: Re: zsh tips for "UNIX Power Tools"
> }
> } My favorite zsh tricks (some of which are not too tricky, but perhaps
> } worth to be mentioned anyways):
> } - I like the globbing features of zsh, especially this one:
> } for i in **/*.gif ; do convert $i ${i:r}.png ; done
>
> It's even easier than that:
>
> for i in **/*.gif; convert $i $i:r.png
Of course - but I tend not to remember this one because I have to use
bash on some systems (well, I hope this will change soon), thus I use
this "do...done" almost always :)
> You don't need the "do ... done" for a one-liner. (The no_short_loops
> option can be used to require do ... done for ksh script compatibility.)
> You don't need the { } for $i:r either (though you would if there were
> not a "." between the "r" and the "png").
Well, I put the { } always, even if I don't need it (a strange habbit of
mine).
> Skipping ahead just a bit:
>
> } This is my last trick for now (and it contains some escape characters,
> } so be sure to copy them as such if you want to try this)
>
> Avoid literal escape characters in 3.1.6 and later by using $'...'.
> The result of $'...' is that the stuff in between the single quotes is
> treated as if you did $(print '...') instead. So now \e is escape:
>
> RPROMPT=$'%{\e[0;33m%}%1v%{\e[0m%}'
Ah. Missed that one. As I'm running out of time for quite a while now, I
only get a few changes to zsh, so I don't even get all those cool
features in my mind... bad luck for me :-(
> } function precmd {
> } # OK, I set the prompt here in my original precmd, but that's not the
> } # issue here :)
> } if jobs % >& /dev/null; then
> } psvar=("There are jobs.")
> } else
> } psvar=("")
> } fi
> } }
>
> Two things: First, you can assign directly to individual elements of an
> array, thusly:
>
> psvar[1]="There are jobs."
[...]
> Second, in 3.1.6-dev-19, you've got the parameter module available, so
> you can avoid running the jobs command and even do some fancier stuff:
Ah, now this is cool.
> # requires zmodload zsh/parameter
> case "$jobstates" in
> (*suspended*)
[...]
> esac
OK, adding the cases with running _and_ suspended jobs was easy now :-)
> Note that if instead you'd said
>
> psvar[1]=()
>
> then that's equivalent to
>
> shift psvar
>
> which is probably not what you want in this case.
Of course.
> } The last line in my precmd (marked "SEE THERE" above") reads like
> } this:
> } (sleep 1 ; show_mode "INSERT") &!
> } [I need the sleep because I have a multiline prompt, so the show_mode
> } would set the indication to the wrong place otherwise]
>
> There's a better way to do this:
>
> # requires setopt prompt_subst
> PROMPT="$PROMPT"'%{$(show_mode INSERT >/dev/tty)%}'
>
> Now the prompt itself runs the initial show_mode, and you don't need any
> background jobs run from precmd. Note that I wrapped it in %{...%} to
> indicate that it shouldn't be counted when computing the prompt width.
> The redirection to /dev/tty is so that the output of show_mode won't
> really become part of the prompt.
Well, OK so far - but the indication still ends up in the wrong place
now. I have a prompt like this:
[more lines]
12:56pm up 6 days, 13:17, 9 users, load average: 0.27, 0.17, 0.11
502 jean-luc@picard (ttypts/15) ~>
I want the indication at the end of the "uptime" line, so using
(sleep 1 ; show_mode "INSERT") &!
does exactly that: move the cursor one line up, to the end of line and
print the indication, and then put the cursor back. Running this as in
your suggestion won't work: the command is evaluated with the cursor
being in it's old position (before drawing the prompt), so the movement
(to place the indication) just moves to the wrong place. Or is there an
option to get around this problem which I also didn't see? :)
> } ### vi-add-eol (unbound) (A) (unbound)
> } ### Move to the end of the line and enter insert mode.
> } vi-add-eol() {
> } show_mode "INSERT"
> } builtin zle .vi-add-eol
> } }
> } zle -N vi-add-eol
> } bindkey -M vicmd "A" vi-add-eol
>
> Note that "A" is already bound to vi-add-eol in the vicmd keymap, so you
> don't need that bindkey command. It's enough to replace the existing
> widget of that name with "zle -N vi-add-eol". Same goes for the rest
> of these widgets, as far as I noticed.
Ah, of course - I played around with all those things a bit too much and
forgot to remove those lines from my .zshry later. Thanks for reminding
me :-)
One last thing: Bart, thanks for your cool and incredible tips on this
list. I learned much from you!
CU & thanks,
Thomas
--
Thomas Köhler Email: jean-luc@xxxxxxxxxxxxxxxxx | LCARS - Linux
<>< WWW: http://jeanluc-picard.de | for Computers
IRC: jeanluc | on All Real
PGP public key available from Homepage! | Starships
Messages sorted by:
Reverse Date,
Date,
Thread,
Author