dotfiles

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

commit f62974d78510ed853e311c8e595b217a91ab5443
parent df63b1ead9e40f9f82b7e0579a5a0328ca36953a
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Mon, 16 Sep 2019 20:55:47 -0400

Improved phone syncing scripts


Former-commit-id: 209403caf0aae874022fcb76e2d48fa5593fa71c
Diffstat:
Mscripts/sync_phone_music | 38+++++++++++++++++++++++++-------------
Ascripts/sync_phone_pictures | 35+++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 13 deletions(-)

diff --git a/scripts/sync_phone_music b/scripts/sync_phone_music @@ -1,17 +1,29 @@ #!/usr/bin/env bash -command -v rsync &>/dev/null || { echo "rsync not found." && exit 1; } -[ $# -ge 1 ] || { echo "The volume is required as an argument." && exit 1; } +if ! command -v rsync &>/dev/null; then + echo "rsync not installed." >&2 + exit 1 +fi -# set creation dates to date of modification -#while read -r f; do echo "$f"; SetFile -d "$(GetFileInfo -m $f)" "$f"; done < <(find .) +do_rsync() { + rsync -uhamP --delete --stats "$@" +} +die() { + echo "$1" >&2 + exit 1 +} +PHONE_DIR="$HOME/phone/Card/Music" +MUSIC_DIR="${MUSIC_DIR:-$HOME/Music}" -diffout=$(diff <(find "$1" -mindepth 1 -type f -not -name .DS_Store | sed 's:^.*Music/::' | sort | tr -d '\r') <(find "$MUSIC_DIR" -mindepth 1 -type f -not -name .DS_Store | sed 's:^.*Music/::' | sort | tr -d '\r')) +[ -d "$PHONE_DIR" ] || die "Phone not present, expected at $PHONE_DIR" +[ -d "$MUSIC_DIR" ] || die "Music dir not present, expected at $MUSIC_DIR" + +less -fR <(do_rsync "$MUSIC_DIR"/ "$PHONE_DIR" -n) + +read -rp "Execute? [Y/n]" -n 1 -s conf +echo + +case "$conf" in + Y|y) do_rsync "$MUSIC_DIR"/ "$PHONE_DIR";; + *) die "User cancelled.";; +esac -echo -e "$1\tvs\t$MUSIC_DIR" -if [ -z "$diffout" ]; then - echo "No difference." -else - echo "$diffout" -fi -find "$1" -name .DS_Store -delete -dot_clean -m . diff --git a/scripts/sync_phone_pictures b/scripts/sync_phone_pictures @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +if ! command -v rsync &>/dev/null; then + echo "rsync not installed." >&2 + exit 1 +fi + +do_rsync() { + rsync -aP --stats "$@" +} +die() { + echo "$1" >&2 + exit 1 +} +set_photo_dir() { + if [ -d "$HOME/Pictures/Imports/" ]; then + PHOTO_IMPORT_DIR="$HOME/Pictures/Imports/" + else + read -rp "Import to: " PHOTO_IMPORT_DIR + [ -d "$PHOTO_IMPORT_DIR" ] || die "$PHOTO_IMPORT_DIR does not exist or is not a directory." + fi +} +PHONE_DIR="$HOME/phone/Phone/DCIM" + +[ -d "$PHONE_DIR" ] || die "Phone not present, expected at $PHONE_DIR" + +less -fR <(do_rsync "$PHOTO_IMPORT_DIR"/ "$PHONE_DIR" -n) + +read -rp "Execute? [Y/n]" -n 1 -s conf +echo + +case "$conf" in + Y|y) do_rsync "$PHONE_DIR" "$PHOTO_IMPORT_DIR"/;; + *) die "User cancelled.";; +esac +