summaryrefslogtreecommitdiffstats
path: root/.local/bin
diff options
context:
space:
mode:
authorTyler Davis <tyler@gluecode.net>2025-01-23 23:57:12 +0000
committerTyler Davis <tyler@gluecode.net>2025-01-23 23:57:12 +0000
commitf8445173ee0f49e7aece3a21b3146453978e1c2b (patch)
tree5c610407163961f4f97db3351dc6a9f70eaf2f3f /.local/bin
parente5f52bd06d1c3f43eeb531895189909ee634b6e0 (diff)
downloaddotfiles-f8445173ee0f49e7aece3a21b3146453978e1c2b.tar.gz
dotfiles-f8445173ee0f49e7aece3a21b3146453978e1c2b.zip
sh: shfmt scripts
Diffstat (limited to '.local/bin')
-rwxr-xr-x.local/bin/confgit.sh18
-rwxr-xr-x.local/bin/fetchgit236
-rwxr-xr-x.local/bin/gitrect-clean132
-rwxr-xr-x.local/bin/gitrect-fix240
-rwxr-xr-x.local/bin/gitrect-update212
5 files changed, 419 insertions, 419 deletions
diff --git a/.local/bin/confgit.sh b/.local/bin/confgit.sh
index e7d2e82..878149b 100755
--- a/.local/bin/confgit.sh
+++ b/.local/bin/confgit.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env sh
-VER="$(git version |cut -d " " -f 3)"
+VER="$(git version | cut -d " " -f 3)"
# Portably get number of procs
OS="$(uname -s)"
@@ -63,12 +63,12 @@ git config --global index.recordOffsetTable true
git config --global log.date iso
git config --global merge.conflictstyle zdiff3
if [ "${VER}" \> "2.45" ]; then
- git config --global pack.allowPackReuse multi # Experimental
- git config --global index.skipHash true # Experimental, will fail earlier than 2.40
- git config --global index.version 4
- git config --global fetch.negotiationAlgorithm skipping # Experimental
- # Additional experimental configs
- git config --global feature.manyFiles true
+ git config --global pack.allowPackReuse multi # Experimental
+ git config --global index.skipHash true # Experimental, will fail earlier than 2.40
+ git config --global index.version 4
+ git config --global fetch.negotiationAlgorithm skipping # Experimental
+ # Additional experimental configs
+ git config --global feature.manyFiles true
fi
git config --global pack.threads "$NPROCS" # Auto-detect threads from CPU
git config --global pack.useBitmapBoundaryTraversal true
@@ -89,8 +89,8 @@ git config --global user.email tyler@gluecode.net
git config --global user.name "Tyler Davis"
if [ "${VER}" \> "2.47" ]; then
- # Only enable reftable by default on git 2.47+
- git config --global init.defaultRefFormat reftable
+ # Only enable reftable by default on git 2.47+
+ git config --global init.defaultRefFormat reftable
fi
# Eagerly detect errors
diff --git a/.local/bin/fetchgit b/.local/bin/fetchgit
index f33a408..f02dfb8 100755
--- a/.local/bin/fetchgit
+++ b/.local/bin/fetchgit
@@ -2,131 +2,131 @@
verbose=0 # Variables to be evaluated as shell arithmetic should be initialized to a default or validated beforehand.
while :; do
- case $1 in
- -v)
- verbose=$((verbose + 1)) # Each -v argument adds 1 to verbosity.
- ;;
- --) # End of all options.
- shift
- break
- ;;
- -?*)
- printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
- ;;
- *) # Default case: If no more options then break out of the loop.
- break ;;
- esac
- shift
+ case $1 in
+ -v)
+ verbose=$((verbose + 1)) # Each -v argument adds 1 to verbosity.
+ ;;
+ --) # End of all options.
+ shift
+ break
+ ;;
+ -?*)
+ printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
+ ;;
+ *) # Default case: If no more options then break out of the loop.
+ break ;;
+ esac
+ shift
done
CWD=$PWD
if [ "$#" -gt 0 ]; then
- for d in "$@"; do
- case $d in
- "."*) cd ${CWD}/${d} ;;
- *) cd ${d} ;;
- esac
+ for d in "$@"; do
+ case $d in
+ "."*) cd ${CWD}/${d} ;;
+ *) cd ${d} ;;
+ esac
if [ $verbose -gt 0 ]; then
echo $PWD
fi
- if [ ! -d .git ]; then # If $PWD/.git doesn't exist
- # then are we in a ".git" dir? jump up one dir
- if [ ${PWD##*/} = ".git" ]; then
- cd ..
- else #Finally, are we at least in a work tree?
- if [ ! $(git rev-parse --is-inside-work-tree) ]; then
- echo "Not in a git directory"
- exit
- fi
- fi
- fi
-
- rems=$(eval "git remote") # list all remotes
- len_rems=${#rems}
- if [ $len_rems -lt 1 ]; then
- # If the list of remotes is zero, we don't do any remote ops
- exit 0
- fi
-
- CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
- # There should always be an origin remote if there is at least one remote
- DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
-
- git fetch --all --prune --quiet
- FETCH_FAILED=$?
-
- git switch --quiet $DEFAULT_BRANCH
-
- if [ $FETCH_FAILED -ne 0 ]; then
- # We should almost always be able to connect to origin
- git pull -q --ff-only --autostash origin $DEFAULT_BRANCH
- else
- if git config remote.upstream.url >/dev/null; then
- git pull -q --ff-only --autostash upstream $DEFAULT_BRANCH
- git push -q origin $DEFAULT_BRANCH
- elif git config remote.upstream.tydavis >/dev/null; then
- git pull -q --ff-only --autostash tydavis $DEFAULT_BRANCH
- git push -q origin $DEFAULT_BRANCH
- else
- git pull -q --ff-only --autostash origin $DEFAULT_BRANCH
- fi
- fi
-
- git switch --quiet $CURRENT_BRANCH
- # Update current branch if out of date
- git pull -q --ff-only --autostash origin $CURRENT_BRANCH
-
- done
+ if [ ! -d .git ]; then # If $PWD/.git doesn't exist
+ # then are we in a ".git" dir? jump up one dir
+ if [ ${PWD##*/} = ".git" ]; then
+ cd ..
+ else #Finally, are we at least in a work tree?
+ if [ ! $(git rev-parse --is-inside-work-tree) ]; then
+ echo "Not in a git directory"
+ exit
+ fi
+ fi
+ fi
+
+ rems=$(eval "git remote") # list all remotes
+ len_rems=${#rems}
+ if [ $len_rems -lt 1 ]; then
+ # If the list of remotes is zero, we don't do any remote ops
+ exit 0
+ fi
+
+ CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
+ # There should always be an origin remote if there is at least one remote
+ DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
+
+ git fetch --all --prune --quiet
+ FETCH_FAILED=$?
+
+ git switch --quiet $DEFAULT_BRANCH
+
+ if [ $FETCH_FAILED -ne 0 ]; then
+ # We should almost always be able to connect to origin
+ git pull -q --ff-only --autostash origin $DEFAULT_BRANCH
+ else
+ if git config remote.upstream.url >/dev/null; then
+ git pull -q --ff-only --autostash upstream $DEFAULT_BRANCH
+ git push -q origin $DEFAULT_BRANCH
+ elif git config remote.upstream.tydavis >/dev/null; then
+ git pull -q --ff-only --autostash tydavis $DEFAULT_BRANCH
+ git push -q origin $DEFAULT_BRANCH
+ else
+ git pull -q --ff-only --autostash origin $DEFAULT_BRANCH
+ fi
+ fi
+
+ git switch --quiet $CURRENT_BRANCH
+ # Update current branch if out of date
+ git pull -q --ff-only --autostash origin $CURRENT_BRANCH
+
+ done
else
- # Current directory invocation
- if [ $verbose -gt 0 ]; then
- echo $PWD
- fi
- if [ ! -d .git ]; then # If $PWD/.git doesn't exist
- # then are we in a ".git" dir? jump up one dir
- if [ ${PWD##*/} = ".git" ]; then
- cd ..
- else #Finally, are we at least in a work tree?
- if [ ! $(git rev-parse --is-inside-work-tree) ]; then
- echo "Not in a git directory"
- exit
- fi
- fi
- fi
-
- rems=$(eval "git remote") # list all remotes
- len_rems=${#rems}
- if [ $len_rems -lt 1 ]; then
- # If the list of remotes is zero, we don't do any remote ops
- exit 0
- fi
-
- CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
- # There should always be an origin remote if there is at least one remote
- DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
-
- git fetch --all --prune --quiet
- FETCH_FAILED=$?
-
- git switch --quiet $DEFAULT_BRANCH
-
- if [ $FETCH_FAILED -ne 0 ]; then
- # We should almost always be able to connect to origin
- git pull -q --ff-only --autostash origin $DEFAULT_BRANCH
- else
- if git config remote.upstream.url >/dev/null; then
- git pull -q --ff-only --autostash upstream $DEFAULT_BRANCH
- git push -q origin $DEFAULT_BRANCH
- elif git config remote.upstream.tydavis >/dev/null; then
- git pull -q --ff-only --autostash tydavis $DEFAULT_BRANCH
- git push -q origin $DEFAULT_BRANCH
- else
- git pull -q --ff-only --autostash origin $DEFAULT_BRANCH
- fi
- fi
-
- git switch --quiet $CURRENT_BRANCH
- # Update current branch if out of date
- git pull -q --ff-only --autostash origin $CURRENT_BRANCH
+ # Current directory invocation
+ if [ $verbose -gt 0 ]; then
+ echo $PWD
+ fi
+ if [ ! -d .git ]; then # If $PWD/.git doesn't exist
+ # then are we in a ".git" dir? jump up one dir
+ if [ ${PWD##*/} = ".git" ]; then
+ cd ..
+ else #Finally, are we at least in a work tree?
+ if [ ! $(git rev-parse --is-inside-work-tree) ]; then
+ echo "Not in a git directory"
+ exit
+ fi
+ fi
+ fi
+
+ rems=$(eval "git remote") # list all remotes
+ len_rems=${#rems}
+ if [ $len_rems -lt 1 ]; then
+ # If the list of remotes is zero, we don't do any remote ops
+ exit 0
+ fi
+
+ CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
+ # There should always be an origin remote if there is at least one remote
+ DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
+
+ git fetch --all --prune --quiet
+ FETCH_FAILED=$?
+
+ git switch --quiet $DEFAULT_BRANCH
+
+ if [ $FETCH_FAILED -ne 0 ]; then
+ # We should almost always be able to connect to origin
+ git pull -q --ff-only --autostash origin $DEFAULT_BRANCH
+ else
+ if git config remote.upstream.url >/dev/null; then
+ git pull -q --ff-only --autostash upstream $DEFAULT_BRANCH
+ git push -q origin $DEFAULT_BRANCH
+ elif git config remote.upstream.tydavis >/dev/null; then
+ git pull -q --ff-only --autostash tydavis $DEFAULT_BRANCH
+ git push -q origin $DEFAULT_BRANCH
+ else
+ git pull -q --ff-only --autostash origin $DEFAULT_BRANCH
+ fi
+ fi
+
+ git switch --quiet $CURRENT_BRANCH
+ # Update current branch if out of date
+ git pull -q --ff-only --autostash origin $CURRENT_BRANCH
fi
diff --git a/.local/bin/gitrect-clean b/.local/bin/gitrect-clean
index 337ceb2..c5bd045 100755
--- a/.local/bin/gitrect-clean
+++ b/.local/bin/gitrect-clean
@@ -5,9 +5,9 @@
# For all directories found in $WORKDIR
# Operate on tempfile
-TEMPFILE="/tmp/gitrect.temp.$(od -t x1 -An -N6 /dev/urandom |tr -d '\n ')"
+TEMPFILE="/tmp/gitrect.temp.$(od -t x1 -An -N6 /dev/urandom | tr -d '\n ')"
touch "$TEMPFILE"
-PREFIX="/tmp/gitrect.prefix.$(od -t x1 -An -N6 /dev/urandom |tr -d '\n ')"
+PREFIX="/tmp/gitrect.prefix.$(od -t x1 -An -N6 /dev/urandom | tr -d '\n ')"
touch "$PREFIX"
# Reset all variables that might be set
@@ -27,51 +27,51 @@ Scan directories in the state file and delete those not referenced:
"
while :; do
- case $1 in
- -h | -\? | --help) # Call a "show_help" function to display a synopsis, then exit.
- echo "$usage"
- exit
- ;;
- -f) # Takes an option argument, ensuring it has been specified.
- if [ -n "$2" ]; then
- DEFAULT_STATE="$2"
- shift
- fi
- ;;
- -f=?*)
- DEFAULT_STATE=${1#*=} # Delete everything up to "=" and assign the remainder.
- ;;
- -f=) # Handle the case of an empty --file=
- printf 'ERROR: "-f" requires a non-empty option argument.\n' >&2
- exit 1
- ;;
- -w) # Takes an option argument, ensuring it has been specified.
- if [ -n "$2" ]; then
- WORKDIR="$2"
- shift
- fi
- ;;
- -w=?*)
- WORKDIR=${1#*=} # Delete everything up to "=" and assign the remainder.
- ;;
- -w=) # Handle the case of an empty --file=
- printf 'ERROR: "-w" requires a non-empty option argument.\n' >&2
- exit 1
- ;;
- -v)
- verbose=$((verbose + 1)) # Each -v argument adds 1 to verbosity.
- ;;
- --) # End of all options.
- shift
- break
- ;;
- -?*)
- printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
- ;;
- *) # Default case: If no more options then break out of the loop.
- break ;;
- esac
- shift
+ case $1 in
+ -h | -\? | --help) # Call a "show_help" function to display a synopsis, then exit.
+ echo "$usage"
+ exit
+ ;;
+ -f) # Takes an option argument, ensuring it has been specified.
+ if [ -n "$2" ]; then
+ DEFAULT_STATE="$2"
+ shift
+ fi
+ ;;
+ -f=?*)
+ DEFAULT_STATE=${1#*=} # Delete everything up to "=" and assign the remainder.
+ ;;
+ -f=) # Handle the case of an empty --file=
+ printf 'ERROR: "-f" requires a non-empty option argument.\n' >&2
+ exit 1
+ ;;
+ -w) # Takes an option argument, ensuring it has been specified.
+ if [ -n "$2" ]; then
+ WORKDIR="$2"
+ shift
+ fi
+ ;;
+ -w=?*)
+ WORKDIR=${1#*=} # Delete everything up to "=" and assign the remainder.
+ ;;
+ -w=) # Handle the case of an empty --file=
+ printf 'ERROR: "-w" requires a non-empty option argument.\n' >&2
+ exit 1
+ ;;
+ -v)
+ verbose=$((verbose + 1)) # Each -v argument adds 1 to verbosity.
+ ;;
+ --) # End of all options.
+ shift
+ break
+ ;;
+ -?*)
+ printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
+ ;;
+ *) # Default case: If no more options then break out of the loop.
+ break ;;
+ esac
+ shift
done
# If there are input files (for example) that follow the options, they
@@ -80,41 +80,41 @@ done
# No posix-compliant way of getting processor count, so leverage OS-specifics
FS_SEPARATOR="/"
if [ "$(uname -s)" = "Darwin" ]; then
- NPROC=$(eval "sysctl -n hw.ncpu")
+ NPROC=$(eval "sysctl -n hw.ncpu")
elif [ "$(uname -s)" = "Linux" ]; then
- NPROC=$(eval "nproc")
+ NPROC=$(eval "nproc")
else
- # Windows uses backslash
- FS_SEPARATOR="\\"
- if [ $verbose -gt 0 ]; then
- echo "cannot detect CPU total"
- fi
+ # Windows uses backslash
+ FS_SEPARATOR="\\"
+ if [ $verbose -gt 0 ]; then
+ echo "cannot detect CPU total"
+ fi
fi
# This double loop is super inefficient, but, it works (?)
while read -r line; do
- dir=$(echo "$line" | cut -d, -f1 | rev | cut -d/ -f2- | rev) #top directories
- echo "${dir}"\$ >>"$PREFIX"
+ dir=$(echo "$line" | cut -d, -f1 | rev | cut -d/ -f2- | rev) #top directories
+ echo "${dir}"\$ >>"$PREFIX"
done <"$DEFAULT_STATE"
uniq "$PREFIX" "$TEMPFILE"
rm "$PREFIX"
while read -r line; do
- dir=$(echo "$line" | cut -d, -f 1)
- echo "$dir" >>"$TEMPFILE"
+ dir=$(echo "$line" | cut -d, -f 1)
+ echo "$dir" >>"$TEMPFILE"
done <"$DEFAULT_STATE"
if [ $verbose -gt 0 ]; then
- find "${WORKDIR}"/* -depth |
- sed -e "s,${WORKDIR}/,," |
- grep -E -v -f "${TEMPFILE}" |
- xargs -P "$NPROC" -t -r -I {} rm -rf "${WORKDIR}""${FS_SEPARATOR}"{}
+ find "${WORKDIR}"/* -depth |
+ sed -e "s,${WORKDIR}/,," |
+ grep -E -v -f "${TEMPFILE}" |
+ xargs -P "$NPROC" -t -r -I {} rm -rf "${WORKDIR}""${FS_SEPARATOR}"{}
else
- find "${WORKDIR}"/* -depth |
- sed -e "s,${WORKDIR}/,," |
- grep -E -v -f "${TEMPFILE}" |
- xargs -P "$NPROC" -r -I {} rm -rf "${WORKDIR}""${FS_SEPARATOR}"{}
+ find "${WORKDIR}"/* -depth |
+ sed -e "s,${WORKDIR}/,," |
+ grep -E -v -f "${TEMPFILE}" |
+ xargs -P "$NPROC" -r -I {} rm -rf "${WORKDIR}""${FS_SEPARATOR}"{}
fi
rm "$TEMPFILE"
diff --git a/.local/bin/gitrect-fix b/.local/bin/gitrect-fix
index de6b498..cd89fa3 100755
--- a/.local/bin/gitrect-fix
+++ b/.local/bin/gitrect-fix
@@ -9,16 +9,15 @@
# For all directories found in $WORKDIR
#
if [ ! "$(command -v git)" ]; then
- echo "git command not found. git must be installed and available in \$PATH to continue"
- exit 1
+ echo "git command not found. git must be installed and available in \$PATH to continue"
+ exit 1
fi
# Reset all variables that might be set
DEFAULT_STATE="$HOME/.local/share/git/repolist"
WORKDIR="$HOME/.code"
verbose=0 # Variables to be evaluated as shell arithmetic should be initialized to a default or validated beforehand.
-GITVER="$(git version |cut -d " " -f 3)"
-
+GITVER="$(git version | cut -d " " -f 3)"
usage="$(basename "$0") [-h] [-v -w WORKDIR -f FILE]
@@ -31,51 +30,51 @@ Set remotes for all git repos and pull new changes where:
"
while :; do
- case $1 in
- -h | -\? | --help) # Call a "show_help" function to display a synopsis, then exit.
- echo "$usage"
- exit
- ;;
- -f) # Takes an option argument, ensuring it has been specified.
- if [ -n "$2" ]; then
- DEFAULT_STATE="$2"
- shift
- fi
- ;;
- -f=?*)
- DEFAULT_STATE=${1#*=} # Delete everything up to "=" and assign the remainder.
- ;;
- -f=) # Handle the case of an empty --file=
- printf 'ERROR: "-f" requires a non-empty option argument.\n' >&2
- exit 1
- ;;
- -w) # Takes an option argument, ensuring it has been specified.
- if [ -n "$2" ]; then
- WORKDIR="$2"
- shift
- fi
- ;;
- -w=?*)
- WORKDIR=${1#*=} # Delete everything up to "=" and assign the remainder.
- ;;
- -w=) # Handle the case of an empty --file=
- printf 'ERROR: "-w" requires a non-empty option argument.\n' >&2
- exit 1
- ;;
- -v)
- verbose=$((verbose + 1)) # Each -v argument adds 1 to verbosity.
- ;;
- --) # End of all options.
- shift
- break
- ;;
- -?*)
- printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
- ;;
- *) # Default case: If no more options then break out of the loop.
- break ;;
- esac
- shift
+ case $1 in
+ -h | -\? | --help) # Call a "show_help" function to display a synopsis, then exit.
+ echo "$usage"
+ exit
+ ;;
+ -f) # Takes an option argument, ensuring it has been specified.
+ if [ -n "$2" ]; then
+ DEFAULT_STATE="$2"
+ shift
+ fi
+ ;;
+ -f=?*)
+ DEFAULT_STATE=${1#*=} # Delete everything up to "=" and assign the remainder.
+ ;;
+ -f=) # Handle the case of an empty --file=
+ printf 'ERROR: "-f" requires a non-empty option argument.\n' >&2
+ exit 1
+ ;;
+ -w) # Takes an option argument, ensuring it has been specified.
+ if [ -n "$2" ]; then
+ WORKDIR="$2"
+ shift
+ fi
+ ;;
+ -w=?*)
+ WORKDIR=${1#*=} # Delete everything up to "=" and assign the remainder.
+ ;;
+ -w=) # Handle the case of an empty --file=
+ printf 'ERROR: "-w" requires a non-empty option argument.\n' >&2
+ exit 1
+ ;;
+ -v)
+ verbose=$((verbose + 1)) # Each -v argument adds 1 to verbosity.
+ ;;
+ --) # End of all options.
+ shift
+ break
+ ;;
+ -?*)
+ printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
+ ;;
+ *) # Default case: If no more options then break out of the loop.
+ break ;;
+ esac
+ shift
done
# No posix-compliant way of getting separator, so leverage OS-specifics
@@ -85,85 +84,86 @@ if [ "$(uname -s)" = "Darwin" ]; then
elif [ "$(uname -s)" = "Linux" ]; then
true # Noop
else
- # Windows uses backslash
- FS_SEPARATOR="\\"
- if [ $verbose -gt 0 ]; then
- echo "cannot detect CPU total"
- fi
+ # Windows uses backslash
+ FS_SEPARATOR="\\"
+ echo "USING BACKSLASH FOR PATH SEPARATOR"
+ if [ $verbose -gt 0 ]; then
+ echo "cannot detect CPU total"
+ fi
fi
while read -r line; do
- dir=$(echo "$line" | cut -d, -f 1)
- remlist=$(echo "$line" | cut -d, -f 2-)
- clone=0 #False
- if [ $verbose -gt 0 ]; then
- echo "Operating on ${WORKDIR}${FS_SEPARATOR}${dir}"
- fi
- if [ ! -d "${WORKDIR}${FS_SEPARATOR}${dir}" ]; then
- #clone repo
- clone=$((clone + 1)) # Set true
- mkdir -p "${WORKDIR}${FS_SEPARATOR}${dir}"
- fi
- cd "${WORKDIR}${FS_SEPARATOR}${dir}" || exit
- if [ $clone -gt 0 ]; then
- if [ ${GITVER} \> "2.45" ]; then
- git init --ref-format=reftable
- else
- git init
- fi
- fi
- if [ $verbose -gt 1 ]; then
- echo "Remote url: ${remlist}"
- fi
- localRemotes=$(eval "git remote")
- len_localRemotes=${#localRemotes}
- echo "${remlist}" | awk -F ',' '{for (i = 1; i <= NF; i++) {printf "%s \n", $i}; printf "\n"}' | while read -r r || [ -n "$r" ]; do
- remoteName=$(echo "$r" | awk -F'=' '{print $1}') # Just get the remote name
- # Allow for blank / newlines during processing
- if [ "${remoteName}" = "" ]; then continue; fi
+ dir=$(echo "$line" | cut -d, -f 1)
+ remlist=$(echo "$line" | cut -d, -f 2-)
+ clone=0 #False
+ if [ $verbose -gt 0 ]; then
+ echo "Operating on ${WORKDIR}${FS_SEPARATOR}${dir}"
+ fi
+ if [ ! -d "${WORKDIR}${FS_SEPARATOR}${dir}" ]; then
+ #clone repo
+ clone=$((clone + 1)) # Set true
+ mkdir -p "${WORKDIR}${FS_SEPARATOR}${dir}"
+ fi
+ cd "${WORKDIR}${FS_SEPARATOR}${dir}" || exit
+ if [ $clone -gt 0 ]; then
+ if [ ${GITVER} \> "2.45" ]; then
+ git init --ref-format=reftable
+ else
+ git init
+ fi
+ fi
+ if [ $verbose -gt 1 ]; then
+ echo "Remote url: ${remlist}"
+ fi
+ localRemotes=$(eval "git remote")
+ len_localRemotes=${#localRemotes}
+ echo "${remlist}" | awk -F ',' '{for (i = 1; i <= NF; i++) {printf "%s \n", $i}; printf "\n"}' | while read -r r || [ -n "$r" ]; do
+ remoteName=$(echo "$r" | awk -F'=' '{print $1}') # Just get the remote name
+ # Allow for blank / newlines during processing
+ if [ "${remoteName}" = "" ]; then continue; fi
- if [ $len_localRemotes -gt 0 ]; then
- remExistsCheck=$(eval "git config remote.${remoteName}.url")
- if [ "${remExistsCheck}" = "" ] ; then
- if [ $verbose -gt 0 ]; then
- echo "Adding remote ${r}"
- fi
- echo "$r" | awk -F'=' '{ print $1, $2; }' | xargs -n 2 git remote add
- else
- if [ $verbose -gt 0 ]; then
- echo "Setting remote ${r}"
- fi
- echo "$r" | awk -F'=' '{ print $1, $2; }' | xargs -n 2 git remote set-url
- fi
- else
- # Remotes not set locally
- if [ $verbose -gt 0 ]; then
- echo "Adding remote ${r}"
- fi
- echo "$r" | awk -F'=' '{ print $1, $2; }' | xargs -n 2 git remote add
- fi
- done
- if [ $verbose -gt 1 ]; then
- echo "Listed remotes for ${dir} are:"
- git remote -v ;
- fi
- if [ $clone -gt 0 ]; then
- git fetch --all
- rev=$(git ls-remote origin | grep HEAD | cut -f 1)
- if [ $verbose -gt 0 ]; then
- echo "Rev: ${rev}"
- fi
- br=$(git ls-remote origin | grep "${rev}" | grep -v HEAD | cut -f 2 | cut -d / -f 3 | head -n 1)
- if [ "$verbose" -gt 0 ]; then
- echo "Branch: ${br}"
- fi
- git switch "$br"
- fi
+ if [ $len_localRemotes -gt 0 ]; then
+ remExistsCheck=$(eval "git config remote.${remoteName}.url")
+ if [ "${remExistsCheck}" = "" ]; then
+ if [ $verbose -gt 0 ]; then
+ echo "Adding remote ${r}"
+ fi
+ echo "$r" | awk -F'=' '{ print $1, $2; }' | xargs -n 2 git remote add
+ else
+ if [ $verbose -gt 0 ]; then
+ echo "Setting remote ${r}"
+ fi
+ echo "$r" | awk -F'=' '{ print $1, $2; }' | xargs -n 2 git remote set-url
+ fi
+ else
+ # Remotes not set locally
+ if [ $verbose -gt 0 ]; then
+ echo "Adding remote ${r}"
+ fi
+ echo "$r" | awk -F'=' '{ print $1, $2; }' | xargs -n 2 git remote add
+ fi
+ done
+ if [ $verbose -gt 1 ]; then
+ echo "Listed remotes for ${dir} are:"
+ git remote -v
+ fi
+ if [ $clone -gt 0 ]; then
+ git fetch --all
+ rev=$(git ls-remote origin | grep HEAD | cut -f 1)
+ if [ $verbose -gt 0 ]; then
+ echo "Rev: ${rev}"
+ fi
+ br=$(git ls-remote origin | grep "${rev}" | grep -v HEAD | cut -f 2 | cut -d / -f 3 | head -n 1)
+ if [ "$verbose" -gt 0 ]; then
+ echo "Branch: ${br}"
+ fi
+ git switch "$br"
+ fi
done <"$DEFAULT_STATE"
# Re-run confgit if it exists
if [ "$(command -v confgit.sh)" ]; then
- confgit.sh
+ confgit.sh
fi
# Update all remotes if we have the fetchgit command
diff --git a/.local/bin/gitrect-update b/.local/bin/gitrect-update
index dcb1c84..fe0d0bc 100755
--- a/.local/bin/gitrect-update
+++ b/.local/bin/gitrect-update
@@ -9,7 +9,7 @@
# For all directories found in $WORKDIR
# Operate on tempfile
-TEMPFILE="/tmp/gitrect.temp.$(od -t x1 -An -N6 /dev/urandom |tr -d '\n ')"
+TEMPFILE="/tmp/gitrect.temp.$(od -t x1 -An -N6 /dev/urandom | tr -d '\n ')"
touch "$TEMPFILE"
# Reset all variables that might be set
@@ -19,8 +19,8 @@ verbose=0 # Variables to be evaluated as shell arithmetic should be initialized
noconfirm=0
if [ ! "$(command -v git)" ]; then
- echo "git command not found. git must be installed and available in \$PATH to continue"
- exit 1
+ echo "git command not found. git must be installed and available in \$PATH to continue"
+ exit 1
fi
usage="$(basename "$0") [-h] [-v -w WORKDIR -f FILE]
@@ -36,62 +36,62 @@ where:
"
while :; do
- case $1 in
- -h | -\? | --help) # Call a "show_help" function to display a synopsis, then exit.
- echo "$usage"
- exit
- ;;
- -f) # Takes an option argument, ensuring it has been specified.
- if [ -n "$2" ]; then
- DEFAULT_STATE=$2
- shift
- fi
- ;;
- -f=?*)
- DEFAULT_STATE=${1#*=} # Delete everything up to "=" and assign the remainder.
- ;;
- -f=) # Handle the case of an empty --file=
- printf 'ERROR: "-f" requires a non-empty option argument.\n' >&2
- exit 1
- ;;
- -w) # Takes an option argument, ensuring it has been specified.
- if [ -n "$2" ]; then
- WORKDIR=$2
- shift
- fi
- ;;
- -w=?*)
- WORKDIR=${1#*=} # Delete everything up to "=" and assign the remainder.
- ;;
- -w=) # Handle the case of an empty --file=
- printf 'ERROR: "-w" requires a non-empty option argument.\n' >&2
- exit 1
- ;;
- -y)
- noconfirm=1
- ;;
- -v)
- verbose=$((verbose + 1)) # Each -v argument adds 1 to verbosity.
- ;;
- --) # End of all options.
- shift
- break
- ;;
- -?*)
- printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
- ;;
- *) # Default case: If no more options then break out of the loop.
- break ;;
- esac
- shift
+ case $1 in
+ -h | -\? | --help) # Call a "show_help" function to display a synopsis, then exit.
+ echo "$usage"
+ exit
+ ;;
+ -f) # Takes an option argument, ensuring it has been specified.
+ if [ -n "$2" ]; then
+ DEFAULT_STATE=$2
+ shift
+ fi
+ ;;
+ -f=?*)
+ DEFAULT_STATE=${1#*=} # Delete everything up to "=" and assign the remainder.
+ ;;
+ -f=) # Handle the case of an empty --file=
+ printf 'ERROR: "-f" requires a non-empty option argument.\n' >&2
+ exit 1
+ ;;
+ -w) # Takes an option argument, ensuring it has been specified.
+ if [ -n "$2" ]; then
+ WORKDIR=$2
+ shift
+ fi
+ ;;
+ -w=?*)
+ WORKDIR=${1#*=} # Delete everything up to "=" and assign the remainder.
+ ;;
+ -w=) # Handle the case of an empty --file=
+ printf 'ERROR: "-w" requires a non-empty option argument.\n' >&2
+ exit 1
+ ;;
+ -y)
+ noconfirm=1
+ ;;
+ -v)
+ verbose=$((verbose + 1)) # Each -v argument adds 1 to verbosity.
+ ;;
+ --) # End of all options.
+ shift
+ break
+ ;;
+ -?*)
+ printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
+ ;;
+ *) # Default case: If no more options then break out of the loop.
+ break ;;
+ esac
+ shift
done
# Make sure local state folder is available
if [ ! -d "$HOME/.local/share" ]; then
- if [ $verbose -gt 0 ]; then
- echo "Creating directory: $HOME/.local/share"
- fi
- mkdir -p "$HOME"/.local/share
+ if [ $verbose -gt 0 ]; then
+ echo "Creating directory: $HOME/.local/share"
+ fi
+ mkdir -p "$HOME"/.local/share
fi
# Rest of the program here.
@@ -104,30 +104,30 @@ LIST=$(eval "find ${WORKDIR} -type d -name .git")
# short/path/here,origin=url1,upstream=url2,...
#
for dirpath in $LIST; do
- # shortpath trims the working directory prefix and the '.git' suffix from the directory
- shortpath=$(eval "echo $dirpath | sed -e 's,${WORKDIR}/,,' -e 's/\/\.git//'")
- if [ $verbose -gt 1 ]; then
- echo "Repository found: ${shortpath}" >&2
- fi
-
- cd "${dirpath}/.." || continue # change into the parent of the git directory
- rems=$(eval "git remote") # list all remotes
- len_rems=${#rems}
- if [ "$len_rems" -lt 1 ]; then
- # If the list of remotes is zero, skip this folder
- continue
- fi
-
- # We haven't skipped the path, so write it to the file
- printf "%s" "$shortpath" >>"$TEMPFILE"
- for r in $rems; do
- url=$(eval "git remote get-url ${r}")
- printf ",%s=%s" "$r" "$url" >>"$TEMPFILE"
- if [ $verbose -gt 1 ]; then
- echo "remote: ${r} ${url} " >&2
- fi
- done
- printf "\n" >>"$TEMPFILE"
+ # shortpath trims the working directory prefix and the '.git' suffix from the directory
+ shortpath=$(eval "echo $dirpath | sed -e 's,${WORKDIR}/,,' -e 's/\/\.git//'")
+ if [ $verbose -gt 1 ]; then
+ echo "Repository found: ${shortpath}" >&2
+ fi
+
+ cd "${dirpath}/.." || continue # change into the parent of the git directory
+ rems=$(eval "git remote") # list all remotes
+ len_rems=${#rems}
+ if [ "$len_rems" -lt 1 ]; then
+ # If the list of remotes is zero, skip this folder
+ continue
+ fi
+
+ # We haven't skipped the path, so write it to the file
+ printf "%s" "$shortpath" >>"$TEMPFILE"
+ for r in $rems; do
+ url=$(eval "git remote get-url ${r}")
+ printf ",%s=%s" "$r" "$url" >>"$TEMPFILE"
+ if [ $verbose -gt 1 ]; then
+ echo "remote: ${r} ${url} " >&2
+ fi
+ done
+ printf "\n" >>"$TEMPFILE"
done
# Sort results
@@ -135,32 +135,32 @@ sort -o "${TEMPFILE}" "${TEMPFILE}"
diffval=$(eval "diff -b ${DEFAULT_STATE} ${TEMPFILE}")
if [ $? -eq 0 ]; then
- if [ $verbose -gt 0 ]; then
- echo "No change. Configuration already up to date." >&2
- fi
- # Cleanup temp file
- rm "${TEMPFILE}"
+ if [ $verbose -gt 0 ]; then
+ echo "No change. Configuration already up to date." >&2
+ fi
+ # Cleanup temp file
+ rm "${TEMPFILE}"
else
- if [ $verbose -gt 0 ]; then
- echo "Diff between current and updated state: " >&2
- echo "$diffval" >&2
- fi
- if [ $noconfirm -ne 0 ]; then
- # Overwite origiaal with the new
- mv "${TEMPFILE}" "${DEFAULT_STATE}"
- else
- printf 'Accept changes (y/n)? \n'
- old_stty_cfg=$(stty -g)
- stty raw -echo
- answer=$(while ! head -c 1 | grep -i '[ny]'; do true; done)
- stty "$old_stty_cfg"
- if [ "$answer" != "${answer#[Yy]}" ]; then
- echo "Updating file..."
- # Overwite origiaal with the new
- mv "${TEMPFILE}" "${DEFAULT_STATE}"
- else
- echo "Discarding changes..."
- rm "${TEMPFILE}"
- fi
- fi
+ if [ $verbose -gt 0 ]; then
+ echo "Diff between current and updated state: " >&2
+ echo "$diffval" >&2
+ fi
+ if [ $noconfirm -ne 0 ]; then
+ # Overwite origiaal with the new
+ mv "${TEMPFILE}" "${DEFAULT_STATE}"
+ else
+ printf 'Accept changes (y/n)? \n'
+ old_stty_cfg=$(stty -g)
+ stty raw -echo
+ answer=$(while ! head -c 1 | grep -i '[ny]'; do true; done)
+ stty "$old_stty_cfg"
+ if [ "$answer" != "${answer#[Yy]}" ]; then
+ echo "Updating file..."
+ # Overwite origiaal with the new
+ mv "${TEMPFILE}" "${DEFAULT_STATE}"
+ else
+ echo "Discarding changes..."
+ rm "${TEMPFILE}"
+ fi
+ fi
fi