.sh

Multi-shell dotfiles manager
git clone https://git.torresjrjr.com/.sh.git
Log | Files | Refs | README | LICENSE

commit 12ad73ca507d0d6bd37e50ac5f6b4d841805b247
parent 5d1ef9ac2e2a7f783e5e0260ec0da7444fd1df9f
Author: Byron Torres <b@torresjrjr.com>
Date:   Wed, 16 Mar 2022 20:58:43 +0000

gfa*: Use wait group

Diffstat:
Mbin/gfa | 29+++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/bin/gfa b/bin/gfa @@ -16,7 +16,6 @@ worker() { git fetch -q 2>&- || { println $n $width 31 "$?" - printf . >/tmp/fifo return } @@ -28,9 +27,9 @@ worker() { done case "$commits" in - # -1) - # env printf '\e[31m%s\e[m\n' ? - # ;; + -1) + println $n $width 31 '?' + ;; 0) println $n $width 0 '.' ;; @@ -38,37 +37,27 @@ worker() { println $n $width 32 "($commits)" ;; esac - - printf . >/tmp/fifo } cwd=$( pwd ) repos=$( find -path '*/.git' -not -path '*/_*' | sort ) -mkfifo /tmp/fifo 2>&- [ "$repos" ] || printf >&2 'No git repos here\n' width="$(echo "$repos" | wc -L)" total="$(echo "$repos" | wc -l)" -env printf '%s\r . \n' $(seq $(( total + 1 ))) +env printf '%s\r ~ \n' $(seq $(( total + 1 ))) env printf '\e[%sA' $(( total + 1 )) env printf '[fetching repos]\r' -{ - n=0 - for dir in $repos - do - worker $n "$dir" & - n=$(( n+=1 )) - sleep 0.1 - done -}& - -for i in $(seq $total) +wg='' n=0 +for dir in $repos do - cat /tmp/fifo >/dev/null + worker $n "$dir" & wg="$wg $! " n=$(( n + 1 )) + sleep 0.05 done +wait $wg env printf '\r\e[%sB' $(( total + 1 ))