Add ability to run dup quietly

This commit is contained in:
Adam Goldsmith 2020-04-26 01:47:14 -04:00
parent 769da953ff
commit 6ca107babf

39
dup
View File

@ -21,16 +21,28 @@ function do_get() {
}
function do_pull() {
dir="$1"
if [ "$stashAndSync" = true ]
then
local do_stash
do_stash=$(git diff)
[ -n "$do_stash" ] && git stash
git pull --rebase
git push
[ -n "$do_stash" ] && git stash pop || true
[ -n "$do_stash" ] && git -C "$dir" stash
git pull -C "$dir" --rebase
git push -C "$dir"
[ -n "$do_stash" ] && git -C "$dir" stash pop || true
else
git pull
git -C "$dir" pull
fi
}
function do_pull_maybe_quiet() {
name="$1"
dir="${2:-$name}"
git_out="$(do_pull $dir)"
if [[ "$quiet" != true || "$git_out" != "Already up to date." ]]
then
echo "Updating $name"
echo "$git_out"
fi
}
@ -41,8 +53,8 @@ function run_script() {
do
if [ -e "$target/$script" ]
then
echo "Running $target$script"
"$target/$script"
$quiet || echo "Running $target$script"
"$target/$script" ${quiet:+-q}
fi
done
}
@ -57,6 +69,7 @@ function maybe_stow() {
fi
}
quiet=false
stow=true
bootstrap=false
stashAndSync=false
@ -75,6 +88,10 @@ do
stashAndSync=true
shift
;;
-q | --quiet)
quiet=true
shift
;;
--)
shift
break
@ -108,15 +125,11 @@ then
maybe_stow "$targets"
elif [ "$bootstrap" != true ]
then
echo "Updating .dotfiles"
do_pull
do_pull_maybe_quiet .dotfiles .
for dir in */
do
echo "Updating $dir"
cd "$dir"
do_pull
cd ..
do_pull_maybe_quiet "$dir"
done
maybe_stow "*/"