From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 540b2600 for ; Thu, 9 May 2019 05:15:36 +0000 (UTC) Received: (qmail 4277 invoked by alias); 9 May 2019 05:15:18 -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: 23943 Received: (qmail 4350 invoked by uid 1010); 9 May 2019 05:15:18 -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.101.2/25440. spamassassin: 3.4.2. Clear:RC:0(195.159.176.226):SA:0(-1.0/5.0):. Processed in 3.344413 secs); 09 May 2019 05:15:18 -0000 X-Envelope-From: gcszu-zsh-users@m.gmane.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at m.gmane.org does not designate permitted sender hosts) X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: zsh-users@zsh.org To: zsh-users@zsh.org From: Emanuel Berg Subject: break loop with key, still don't exit the program + code Date: Thu, 09 May 2019 07:14:29 +0200 Message-ID: <8636loky4q.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Mail-Copies-To: never Cancel-Lock: sha1:QiwOn9mKJ2a8be4byK2md3fA5KA= How can I prematurely break from a loop, or a deliberately infinite loop for that matter, while still don't exit the program? I.e., #! /bin/zsh while (true); do # do computations done # when interrupted by the user, # do a summary of the computations # and output # only then, exit program The particular use case is yanked last. Feel free to comment on the code as well, of course! The purpose is I stretch for ~1h every day (e.g. today 1h 3m 55s) and use the below functions to signal when too change position. Only sometimes, I don't do the entire program, say I stretch for ~30m or whatever instead. With the output from the 'stretch' program, when interrupted prematurely, I can do $ echo $(s2hms $(( 28*65 )) ) 30m 20s and write it down it in my flipboard. That way, digits won't lie :) Only, I'd like to have this automated so whenever 'stretch' is interrupted, last thing it'll do is make the computation and output it. Thanks in advance :) #! /bin/zsh # https://dataswamp.org/~incal/conf/.zsh/stretch play-stretch-sound () { local sound=~/bo/up.mp3 if [[ -f $sound ]]; then omx-play-whatever $OMX_SND_MOD $sound else echo "Error: Can't find sound file: $sound" >&2 fi } stretch () { local init_time=19 local s_time=65 local stretches=70 local total_s=$(( $s_time * $stretches )) local total_time="$(s2hms ${total_s})" echo "Total time: $total_time (${stretches}*${s_time}s)" play-stretch-sound local current=0 sleep $init_time echo -n "current:" repeat $stretches { current=$(( $current + 1 )) echo -n " $current" play-stretch-sound sleep $s_time } repeat 2 play-stretch-sound } alias st=stretch # https://dataswamp.org/~incal/conf/.zsh/time s2hms () { local secs=$1 local time_string time_string=$(units -t $secs\s hms) local -a data data=("${(@s/;/)time_string}") local h=$data[1] local m=$data[2] local s=$data[3] local out [[ $h > 0 ]] && out="${h}h " [[ $m > 0 ]] && out+="${m}m " [[ $s > 0 ]] && out+="${s}s" echo $out } alias hms=s2hms -- underground experts united http://user.it.uu.se/~embe8573