diff --git a/.local/bin/sync-git-repos b/.local/bin/sync-git-repos index d1fce9e..6b93770 100755 --- a/.local/bin/sync-git-repos +++ b/.local/bin/sync-git-repos @@ -1,4 +1,7 @@ -#! /usr/bin/sh +#! /usr/bin/bash + +set -euo pipefail +IFS=$'\n\t' REPO_ROOT_FILE="$(systemd-path user-state-private)"/repo-roots/repo-roots @@ -12,18 +15,25 @@ sync_repo () { repo=$1 echo git-sync "${repo}" - ( cd "${repo}" && "$(systemd-path user-state-private)"/git-sync/git-sync sync ) + ( cd "${repo}" && "$(systemd-path user-state-private)"/git-sync/git-sync sync ) || true echo } -if [ "list" = "$1" ]; then - while read -r repo_root; do - list_repos "${repo_root}" - done < "${REPO_ROOT_FILE}" -else - while read -r repo_root; do - for repo in $(list_repos "${repo_root}"); do - sync_repo "${repo}" - done - done < "${REPO_ROOT_FILE}" -fi +case "${1:-sync}" in + "list") + while read -r repo_root; do + list_repos "${repo_root}" + done < "${REPO_ROOT_FILE}" + ;; + "sync") + while read -r repo_root; do + for repo in $(list_repos "${repo_root}"); do + sync_repo "${repo}" + done + done < "${REPO_ROOT_FILE}" + ;; + *) + echo Unknown option \""$1"\" + exit 1 + ;; +esac