dotfiles/.local/bin/sync-git-repos

29 lines
654 B
Bash
Executable file

#! /usr/bin/sh
REPO_ROOT_FILE="$(systemd-path user-state-private)"/repo-roots/repo-roots
list_repos () {
repo_root=$1
find "${repo_root}" -maxdepth 2 -name .git -type d -exec dirname {} \;
}
sync_repo () {
repo=$1
echo git-sync "${repo}"
( cd "${repo}" && "$(systemd-path user-state-private)"/git-sync/git-sync -n -s sync )
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