diff --git a/dup b/dup index 1f3dd5f..36e40f8 100755 --- a/dup +++ b/dup @@ -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 "*/"