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
1 changed files with 26 additions and 13 deletions

39
dup
View File

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