dotfiles

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

commit c29217a44af8642f2dcd7404381b53ae371fcd58
parent 3b555651b81aa668abb4843eb5cd890f04cb31d9
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Thu,  5 Sep 2019 13:17:59 -0400

Various scripts to help manage my phone


Former-commit-id: 0cb5f40ea918f24bf90be0621602f99541a15d7c
Diffstat:
Ascripts/mount_phone | 30++++++++++++++++++++++++++++++
Ascripts/sync_phone_music | 17+++++++++++++++++
Ascripts/sync_phone_playlist | 10++++++++++
3 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/scripts/mount_phone b/scripts/mount_phone @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# set -x +if ! command -v simple-mtpfs &>/dev/null; then + echo "simple-mtpfs not installed." >&2 + exit 1 +fi + +mountdir="/Users/alex/phone" +clean_up() { + echo "Exiting..." + if kill -0 "$mtpfs_pid" &> /dev/null; then + kill "$mtpfs_pid" + fi + [ ! -d "$mountpoint" ] || rm -r "$mountpoint"; + [ ! -L "$mountdir" ] || rm "$mountdir"; +} +trap clean_up INT TERM EXIT + +try_to_mount() { + echo "Mounting phone..." + simple-mtpfs -f "$mountpoint" & + mtpfs_pid=$! +} + +mountpoint=$(mktemp -d) +try_to_mount +ln -s "$mountpoint" "$mountdir" +echo "Mounted at $mountdir (=> $mountpoint)." +echo "Send interrupt to unmount." +wait diff --git a/scripts/sync_phone_music b/scripts/sync_phone_music @@ -0,0 +1,17 @@ +#!/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; } + +# set creation dates to date of modification +#while read -r f; do echo "$f"; SetFile -d "$(GetFileInfo -m $f)" "$f"; done < <(find .) + +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')) + +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_playlist b/scripts/sync_phone_playlist @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +[ $# -eq 2 ] || { echo "Please pass the playlist and playlist dir path as an argument." && exit 1; } + +if command -v gsed &>/dev/null; then + sedcmd="gsed" +else + sedcmd="sed" +fi + +cat "$1" | tr '\r' '\n' | $sedcmd 's:/Volumes.*Music/:../Music/:' > "$2"/"${1##*/}"