# HG changeset patch # User Sean E. Russell # Date 1637426227 21600 # Sat Nov 20 10:37:07 2021 -0600 # Node ID 972d9ff36bf2ba0f015cdc74f2c8adf756e07c6b # Parent 5371b318d4390dda7280d215a9ea169fcc9744ab Adds -1 (no-daemon) mode & generifies file suffix (although, _a_ suffix is still required diff --git a/synctodo b/synctodo --- a/synctodo +++ b/synctodo @@ -7,6 +7,7 @@ printf "USAGE: synctodo [-dh] -d Debug -h Help (exits) + -1 Sync up a file and exit (no-daemon mode) the path to the todo.txt-format file Finds all SyncThing *.sync-conflict* files for a given file and merges them, @@ -23,7 +24,7 @@ " $backupdir } -while getopts dh opt ; do +while getopts dh1 opt ; do case $opt in d) set -x @@ -32,6 +33,9 @@ usage exit 0 ;; + 1) + local onetime=1 + ;; ?) print $OPTERR usage @@ -46,7 +50,8 @@ exit 1 fi -ROOT=${FILE%.txt} +ROOT=$FILE:r +SUFF=$FILE:t:e # merge [F] => F # merge [F₀, F₁] => [F₀₁] @@ -57,6 +62,7 @@ 0) ;; 1) + local onetime=1 ;; 2) local tmpfile=$(tempname -d /tmp mergefile) @@ -74,7 +80,7 @@ } function mergeBased() { - CONFL=(${ROOT}.sync-conflict*.txt) + CONFL=(${ROOT}.sync-conflict*.${SUFF}) RES=$(merge $CONFL $FILE) # cleanup set -e @@ -95,14 +101,17 @@ printf "Backups will be in %s\n" "$backupdir" printf "Initial cleanup\n" -fs=(${ROOT}.sync-conflict*.txt(N)) +fs=(${ROOT}.sync-conflict*.${SUFF}(N)) [[ ${#fs} -gt 0 ]] && mergeBased +# Exit if the user specified -1 +[[ -n $onetime ]] && exit 0 + printf "Watching %s" "$FILE" fswatch -l 5 --event Created --event IsFile "$(dirname $FILE)" | \ while read -r event ; do # because of the fswatch bug, we have to check this the hard way - echo "$event" | grep -qP "^${ROOT}\.sync-conflict.*\.txt$" + echo "$event" | grep -qP "^${ROOT}\.sync-conflict.*\.${SUFF}$" if [[ $? -eq 0 ]]; then mergeBased fi