Post A2abO3MV7eRsLqDo00 by wolf480pl@mstdn.io
(DIR) More posts by wolf480pl@mstdn.io
(DIR) Post #A2aZnaQJ8d0eDk38qW by brad@weeaboo.space
2020-12-26T09:37:40.756573Z
0 likes, 0 repeats
I want a version of the sleep command that shows me a live countdown in my shell
(DIR) Post #A2aa4toAJqeRGSSqVE by wolf480pl@mstdn.io
2020-12-26T09:40:47Z
0 likes, 0 repeats
@brad for ((i=10; i > 0; i++)); do echo $i; sleep 1; done; echo 0
(DIR) Post #A2aa78GdWzQGgiqX2W by wolf480pl@mstdn.io
2020-12-26T09:41:13Z
0 likes, 0 repeats
@brad you can alias it or make it a script
(DIR) Post #A2aaCl0kuT5aIX6HEu by wolf480pl@mstdn.io
2020-12-26T09:42:13Z
0 likes, 0 repeats
@brad also, you may need to move everything from the loop body to the loop condition in order to preserve error behaviour
(DIR) Post #A2aacTbkEnntqqfKCG by tdemin@udongein.xyz
2020-12-26T09:46:54.799478Z
0 likes, 0 repeats
@wolf480pl @brad > i > 0; i++hello endless loop
(DIR) Post #A2aaf48ZOR87izFnZg by brad@weeaboo.space
2020-12-26T09:47:21.586568Z
0 likes, 0 repeats
@wolf480pl this seems to count up instead of down (and forever) and I'm not really sure how to use it how I'd use sleep normally. Would I swap out the sleep command here with the one I want to use? I sometimes set like a 2 hour sleep before a backup alias because I'm doing other things that are using the network bandwidth, so I wanted to see something like "2 hours 0 minutes 0 seconds remaining" counting down to 0 everything when it actually happens
(DIR) Post #A2aan4uaOiFkRXX9HM by brad@weeaboo.space
2020-12-26T09:48:49.432152Z
0 likes, 0 repeats
@wolf480pl "loop body" and "loop condition" aren't very intuitive to me. I guess "for" is maybe the condition since there's no "if" here, the body must be the "other" part. I'm still not entirely sure what it should be rewritten as.
(DIR) Post #A2abO3MV7eRsLqDo00 by wolf480pl@mstdn.io
2020-12-26T09:55:28Z
1 likes, 0 repeats
@brad sorry I screwed up, should be i--.How you'd use it to delay a command?Put a semicolon after it, then your command.for ((i = 7200; i > 0; i--)); do echo $i; sleep1; done; echo 0; ./do_backup.shor sththough I guess that long a countdown in seconds is far from ideal...
(DIR) Post #A2abfcyPyMqLinKxn6 by brad@weeaboo.space
2020-12-26T09:58:40.360172Z
0 likes, 0 repeats
@wolf480pl thank you for the effort, but it bothers me a bit too much to be likely to actually use. like, I *always* use units with the sleep command, so having to think of things in seconds to make use of this would already be a showstopper for me when I'm used to `sleep 2h; bkup` and such. I'm sure I could throw a bit more scripting at it and get something to convert units to seconds... I don't really feel like it.
(DIR) Post #A2abjuPX5CzUxd3rLU by wolf480pl@mstdn.io
2020-12-26T09:59:24Z
0 likes, 0 repeats
@brad sorry I'm dumb, forgot bash for (()) is special.With while loops it's easier:while <condition>; do <body>; done;so eg. I could do:while true; do pdflatex foo.tex mupdf foo.pdfdonebut instead I do:while pdflatex foo.tex; do mupdf foo.pdfdoneso that when the pdflatex command fails, the loop stops.I don't think bash's arithmetic for supports such a thing, so you'd probably need to use a while break or something like that
(DIR) Post #A2abnSKrPNyR2qZEbg by wolf480pl@mstdn.io
2020-12-26T10:00:04Z
1 likes, 0 repeats
@brad yeaaah, would be nice if it was a proper command with pretty-printing, fuzzy-parsing and all that....
(DIR) Post #A2acGY5J71RDH1AHp2 by wolf480pl@mstdn.io
2020-12-26T10:05:19Z
0 likes, 0 repeats
@tdemin @brad yes am stupid
(DIR) Post #A2aha2XIcNmyzRN5ZQ by wzqtparor@mstdn.io
2020-12-26T11:04:51Z
1 likes, 0 repeats
There are quite some shell scripts doing this, but if you want a really simple one:https://github.com/antonmedv/countdown@wolf480pl @brad
(DIR) Post #A2aph6fuQZEDUFHNFQ by brad@weeaboo.space
2020-12-26T12:35:49.321067Z
0 likes, 0 repeats
@wzqtparor @wolf480pl whoa, this looks amazing!