.sh

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

commit 5d1ef9ac2e2a7f783e5e0260ec0da7444fd1df9f
parent 19c9f9ff9b48cbad0ec91a15a5311c1c71f694ac
Author: Byron Torres <b@torresjrjr.com>
Date:   Wed, 16 Mar 2022 14:00:11 +0000

New gfa*

Diffstat:
Abin/gfa | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+), 0 deletions(-)

diff --git a/bin/gfa b/bin/gfa @@ -0,0 +1,74 @@ +#!/bin/sh -u +# gfa -- fetch all git repos in cwd + +println() { + local line=$(( $1 + 1 )) column=$2 colour=$3 text=$4 + env printf '\r\e[%sB\e[%sC\e[%sm%s\e[m\r\e[%sA\e[%sC' \ + $line $column $colour "$text" $line $column +} + +worker() { + local n=$1 + local dir="${2%/.git}" + cd "$cwd" + cd "$dir" + println $n 0 0 "${dir#./}" + + git fetch -q 2>&- || { + println $n $width 31 "$?" + printf . >/tmp/fifo + return + } + + commits=0 + for rev in master main + do + add=$( git log --oneline origin/$rev ^$rev 2>&- | wc -l ) + commits=$(( $commits + $add )) + done + + case "$commits" in + # -1) + # env printf '\e[31m%s\e[m\n' ? + # ;; + 0) + println $n $width 0 '.' + ;; + *) + 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 '\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) +do + cat /tmp/fifo >/dev/null +done + +env printf '\r\e[%sB' $(( total + 1 ))