zsh-users
 help / color / mirror / code / Atom feed
* Honoring a command
@ 2004-04-01 17:03 DervishD
  2004-04-03 21:43 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: DervishD @ 2004-04-01 17:03 UTC (permalink / raw)
  To: Zsh Users

    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/


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-04-05 10:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-01 17:03 Honoring a command DervishD
2004-04-03 21:43 ` Bart Schaefer
2004-04-04 11:16   ` DervishD
2004-04-05  1:09     ` Bart Schaefer
2004-04-05  9:59       ` DervishD

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).