From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8773 invoked by alias); 19 Oct 2017 13:03:59 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 22946 Received: (qmail 28195 invoked by uid 1010); 19 Oct 2017 13:03:59 -0000 X-Qmail-Scanner-Diagnostics: from 195.159.176.226 by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(195.159.176.226):SA:0(-0.9/5.0):. Processed in 3.88086 secs); 19 Oct 2017 13:03:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RDNS_NONE autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: gcszu-zsh-users@m.gmane.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: zsh-users@zsh.org To: zsh-users@zsh.org From: Emanuel Berg Subject: Re: s2hms Date: Thu, 19 Oct 2017 15:03:01 +0200 Message-ID: <86r2tzz3wa.fsf@zoho.com> References: <86h8uw14ho.fsf@zoho.com> <20171019084938.GA11689@aurora-borealis.phear.org> Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: usenet@blaine.gmane.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Mail-Copies-To: never Cancel-Lock: sha1:j85e+x2+ahBm5x09D0BPDS5vJxk= Marc Chantreux wrote: > you don't need the $data buffer as you can > read directly in varibles. my (untested) > version should be more like local secs=${1?duration in seconds} it= out= unknown file attribute Also, what's with the strange chars: \240 two times? > s2hms () { > # clean error message when no argument passed > local secs=${1?duration in seconds} it= out= > local -a fields=( h m s ) > local -A duration > > # duration\[$^fields] is a short for > # duration\[h]duration\[m] duration\[s] > > units -t $secs\s hms | > IFS=\; read duration\[$^fields] > > > # use mathematical context to do math > # also: a value is 0 or >0 so just test if it's >0 > > for it ($fields) > (( duration[it])) && out+="$duration[$it]$it" > > print $out > } -- underground experts united http://user.it.uu.se/~embe8573