dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 980c807a9e810cb1589c3cd4764021e36be8437e
parent bae2f21d32f3d408578906a183d79f659ecbe493
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Sun,  8 Nov 2020 18:00:37 +0100

sync_phone_music: add option to skip dry-running


Former-commit-id: 46196a6f25d451e6bd52c518f8d0dacbdb3f62f4
Diffstat:
Mscripts/sync_phone_music | 59++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 44 insertions(+), 15 deletions(-)

diff --git a/scripts/sync_phone_music b/scripts/sync_phone_music @@ -28,23 +28,52 @@ PHONE_DIR="/storage/5D6D-E047/Music" MUSIC_DIR="${MUSIC_DIR:-$HOME/Music}" [ -d "$MUSIC_DIR" ] || die "Music dir not present, expected at $MUSIC_DIR" -[ ! -z "$(adb devices | grep device$)" ] || die "Phone not connected." +[ -n "$(adb devices | grep device$)" ] || die "Phone not connected." PARAMS="" +while [ $(($#)) -ne 0 ]; do + case "$1" in + -y) + skip_dry_run=1 + shift + ;; + -h|--help) + echo "Pass -y to skip dry run." + exit 0 + ;; + --) # end arg parsing + shift + break + ;; + -*) # unsupported flags + echo "Unsupported flag $1" >&2 + exit 1 + ;; + *) # preserve positional arguments + PARAMS="$PARAMS $1" + shift + ;; + esac +done +eval set -- "$PARAMS" # Piping directly didn't work for some reason, less wouldn't page it -outfile=$(mktemp) -trap "rm $outfile" INT TERM EXIT -echo "Calculating differences..." -{ do_sync "$MUSIC_DIR"/ "$PHONE_DIR" --dry-run; } &> "$outfile" -less -fR "$outfile" && rm "$outfile" -trap - INT TERM EXIT - -read -rp "Execute? [Y/n]" -n 1 -s conf -echo - -case "$conf" in - Y|y) do_sync "$MUSIC_DIR"/ "$PHONE_DIR";; - *) die "User cancelled.";; -esac +if [ -z "$skip_dry_run" ]; then + outfile=$(mktemp) + trap "rm $outfile" INT TERM EXIT + echo "Calculating differences..." + { do_sync "$MUSIC_DIR"/ "$PHONE_DIR" --dry-run; } &> "$outfile" + less -fR "$outfile" && rm "$outfile" + trap - INT TERM EXIT + + read -rp "Execute? [Y/n]" -n 1 -s conf + echo + + case "$conf" in + Y|y) do_sync "$MUSIC_DIR"/ "$PHONE_DIR";; + *) die "User cancelled.";; + esac + else + do_sync "$MUSIC_DIR"/ "$PHONE_DIR" +fi