From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18837 invoked from network); 4 Mar 2000 12:22:02 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 4 Mar 2000 12:22:02 -0000 Received: (qmail 739 invoked by alias); 4 Mar 2000 12:21:35 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 2941 Received: (qmail 702 invoked from network); 4 Mar 2000 12:21:32 -0000 Date: Sat, 4 Mar 2000 13:05:47 +0100 From: =?iso-8859-1?Q?Thomas_K=F6hler?= To: zsh-users@sunsite.auc.dk Subject: Re: zsh tips for "UNIX Power Tools" Message-ID: <20000304130547.D1805@picard.franken.de> Mail-Followup-To: =?iso-8859-1?Q?Thomas_K=F6hler?= , zsh-users@sunsite.auc.dk References: <28174.952013581@jpeek.com> <20000303123932.A11036@picard.franken.de> <87k8jjwt6h.fsf@cenderis.demon.co.uk> <1000304054014.ZM21187@candle.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable User-Agent: Mutt/1.1.7i In-Reply-To: <1000304054014.ZM21187@candle.brasslantern.com>; from schaefer@candle.brasslantern.com on Sat, Mar 04, 2000 at 06:40:44AM +0100 X-Operating-System: Linux picard 2.2.14 X-Editor: VIM - Vi IMproved 5.6 http://www.vim.org/ X-IRC: tirc-1.2; Nick: jeanluc X-URL: http://jeanluc-picard.de/ On Sat, Mar 04, 2000 at 06:40:44AM +0100, Bart Schaefer wrote: >=20 > On Mar 3, 12:39pm, Thomas K=F6hler 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 >=20 > It's even easier than that: >=20 > 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: >=20 > } 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) >=20 > 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: >=20 > RPROMPT=3D$'%{\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=3D("There are jobs.") > } else > } psvar=3D("") > } fi > } } >=20 > Two things: First, you can assign directly to individual elements of an > array, thusly: >=20 > psvar[1]=3D"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 >=20 > psvar[1]=3D() >=20 > then that's equivalent to >=20 > shift psvar >=20 > 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] >=20 > There's a better way to do this: >=20 > # requires setopt prompt_subst > PROMPT=3D"$PROMPT"'%{$(show_mode INSERT >/dev/tty)%}' >=20 > 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 >=20 > 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 --=20 Thomas K=F6hler Email: jean-luc@picard.franken.de | LCARS - Linux <>< WWW: http://jeanluc-picard.de | for Computers IRC: jeanluc | on All Real PGP public key available from Homepage! | Starships