zsh-users
 help / color / mirror / code / Atom feed
From: DervishD <raul@pleyades.net>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: Honoring a command
Date: Thu, 1 Apr 2004 19:03:13 +0200	[thread overview]
Message-ID: <20040401170312.GA25965@DervishD> (raw)

    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/


             reply	other threads:[~2004-04-01 17:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-01 17:03 DervishD [this message]
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

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=20040401170312.GA25965@DervishD \
    --to=raul@pleyades.net \
    --cc=zsh-users@sunsite.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).