Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Honoring a command
- X-seq: zsh-users 7309
- From: DervishD <raul@xxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxxxxx>
- Subject: Honoring a command
- Date: Thu, 1 Apr 2004 19:03:13 +0200
- Mail-followup-to: Zsh Users <zsh-users@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: Pleyades
Hi all :)
A couple of weeks ago one of the list members asked about
justifying some script output, and I decided to er.. inspire from
(that is, steal) that idea and I want to modify some scripts I have
from something like:
Printing file whatever.ps... done.
to something like:
Printing file whatever.ps [ok]
justified to the screen width.
This is not a problem since thanks to this list I know how to do
the justification, but the question is that I want to modify code
like this:
print -n "Doing whatever command..." >&2
whatever.command 2> /dev/null || { print " error! Message" >&2; return 1; }
print " done." >&2
to this:
verbosely_do "Doing whatever command" whatever.command \
|| { print "Message" >&2; return 1;}
The function 'verbosely_do' is pretty easy:
function verbosely_do() {
emulate -L zsh
print -n ${(r:(($WIDTH)):)1} >&2
$* || {
print "[!]" >&2
return 1
}
print "[*]" >&2
return 0
}
$WIDTH is defined elsewhere or can be even a fixed number, and
the symbols may have colors, etc... The important point is that the
function prettyprints some messages and run the commands. Please,
pretend that you don't notice that bare '$*' that may expand to an
empty string ;)) That will corrected later.
The problem I see is: what will happen if the command has
redirections, metacharacters, quotes, variable references, etc.? Will
it be run by 'verbosely_do' correctly, that is, exactly in the same
way as it was run in the code without 'verbosely_do', or should I
preprocess it in some way? As an example:
verbosely_do "Command" chown -R `id -un`:`id -gn` "$SOURCES"
Although it may be any command that will run correctly given
itself alone in any script.
Thanks a lot and please excuse me for such weird question O:)
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author