.sh

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

commit 9daafb33f66d1ed30028a2203059922bbbc0cb0f
parent 8e010791298575b4a89d17673a6fae30fe95ef45
Author: Byron Torres <b@torresjrjr.com>
Date:   Tue, 18 Apr 2023 11:02:17 +0100

gfa*: make tmp files per process

Diffstat:
Mbin/gfa | 35++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/bin/gfa b/bin/gfa @@ -4,22 +4,22 @@ println() { { flock 3 line=$1 column=$2 colour=$3 text=$4 - lines=$( wc -l </tmp/gfa-lines ) + lines=$( wc -l <"$run/lines" ) offset=$(( $lines - $line + 1)) env printf '\r\e[%sA\e[%sC\e[%sm%s\e[m\r\e[%sB\r' \ $offset $column \ $colour "$text" \ $offset - } 3</tmp/gfa-mutex + } 3<"$run/mutex" } worker() { - local n="$( head -n1 /tmp/gfa-inits )" + local n="$( head -n1 "$run/inits" )" local dir="${1%/.git}" { flock 3 - env printf '\n' | tee -a /tmp/gfa-lines - } 3</tmp/gfa-mutex + env printf '\n' | tee -a "$run/lines" + } 3<"$run/mutex" cd "$cwd" cd "$dir" @@ -27,8 +27,8 @@ worker() { git fetch -q 2>&- || { println $n $width 31 "$?" - env printf '\n' >/tmp/gfa-done - env printf '\n' >/tmp/gfa-finis + env printf '\n' >"$run/done" + env printf '\n' >"$run/finis" return } @@ -51,8 +51,8 @@ worker() { ;; esac - env printf '\n' >/tmp/gfa-done - env printf '\n' >/tmp/gfa-finis + env printf '\n' >"$run/done" + env printf '\n' >"$run/finis" return } @@ -69,11 +69,10 @@ repos=$( find -maxdepth "$maxdepth" -path '*/.git' -not -path '*/_*' | sort ) width="$(printf '%s\n' "$repos" | wc -L)" total="$(printf '%s\n' "$repos" | wc -l)" -touch /tmp/gfa-dummy -rm /tmp/gfa-* -touch /tmp/gfa-lines -touch /tmp/gfa-mutex -mkfifo /tmp/gfa-inits /tmp/gfa-finis /tmp/gfa-done +run=$(mktemp -d) +touch "$run/lines" +touch "$run/mutex" +mkfifo "$run/inits" "$run/finis" "$run/done" env printf '[fetching %s repos]\n' "$total" @@ -86,7 +85,7 @@ worker_manager() { for N in $(seq $total) do [ "$N" -gt $winsz ] && { - head -n1 /tmp/gfa-finis >/dev/null + head -n1 "$run/finis" >/dev/null } env printf '%s\n' "$N" @@ -94,9 +93,11 @@ worker_manager() { done } -worker_manager >/tmp/gfa-inits & +worker_manager >"$run/inits" & for N in $(seq $total) do - head -n1 /tmp/gfa-done >/dev/null + head -n1 "$run/done" >/dev/null done + +rm -r "$run"