From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: Jerry Peek <jpeek@jpeek.com>, zsh-users@sunsite.auc.dk
Subject: Re: zsh tips for "UNIX Power Tools"
Date: Sat, 4 Mar 2000 05:40:13 +0000 [thread overview]
Message-ID: <1000304054014.ZM21187@candle.brasslantern.com> (raw)
In-Reply-To: =?iso-8859-1?Q?=3C20000303123932=2EA11036=40picard=2Efranken?= =?iso-8859-1?Q?=2Ede=3E?= =?iso-8859-1?Q?Comments=3A_In_reply_to_Thomas_K=F6hler_=3Cjean-luc=40pica?= =?iso-8859-1?Q?rd=2Efranken=2Ede=3E?= =?iso-8859-1?Q?________=22Re=3A_zsh_tips_for_=22UNIX_Power_Tools=22=22_?= =?iso-8859-1?Q?=28Mar__3=2C_12=3A39pm=29?=
In-Reply-To: <87k8jjwt6h.fsf@cenderis.demon.co.uk>
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
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").
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%}'
} 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."
That way you can use other positions in $psvar for other things, without
reassigning the whole thing every time.
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:
# requires zmodload zsh/parameter
case "$jobstates" in
(*suspended*)
psvar[1]="There are stopped jobs.";;
(*running*)
psvar[1]="There are running jobs.";;
(*)
psvar[1]="";;
esac
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.
} 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.
} ### 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.
On Mar 3, 11:05pm, Bruce Stephens wrote:
} Subject: Re: zsh tips for "UNIX Power Tools"
}
} > chmod 755 **/*(/)
} > chmod 644 **/*(.)
}
} What's wrong with
}
} chmod -R go+rX .
It changes the group and other execute permissions of plain files if the
user execute permission was already set. That's obviously not what 644
accomplishes on plain files in Thomas's example.
Besides, not everyone has GNU chmod.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
next prev parent reply other threads:[~2000-03-04 5:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-03-02 16:13 Jerry Peek
2000-03-03 11:39 ` Thomas Köhler
2000-03-03 14:17 ` Jerry Peek
2000-03-03 23:05 ` Bruce Stephens
2000-03-04 5:40 ` Bart Schaefer [this message]
2000-03-04 12:05 ` Thomas Köhler
2000-03-04 16:38 ` Bart Schaefer
2000-03-04 17:18 ` Bart Schaefer
2000-03-04 12:31 ` Bruce Stephens
2000-03-04 11:43 ` Thomas Köhler
2000-03-04 12:43 ` Bruce Stephens
2000-03-04 12:22 ` Vincent Lefevre
2000-03-04 18:12 ` Bart Schaefer
2000-03-05 23:19 ` Vincent Lefevre
2000-03-06 0:30 ` Bart Schaefer
2000-03-06 20:51 ` Thomas Köhler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1000304054014.ZM21187@candle.brasslantern.com \
--to=schaefer@candle.brasslantern.com \
--cc=jpeek@jpeek.com \
--cc=zsh-users@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).