From 8395cf42d5ba294bd11163e5818e41d24ce4e537 Mon Sep 17 00:00:00 2001 From: Dominik Schrempf Date: Sun, 23 Feb 2020 12:00:03 +0100 Subject: [PATCH] search directory only --- syncthing-resolve-conflicts | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/syncthing-resolve-conflicts b/syncthing-resolve-conflicts index 7e40dc9..7e62bc5 100755 --- a/syncthing-resolve-conflicts +++ b/syncthing-resolve-conflicts @@ -9,6 +9,7 @@ declare -r myver='1.0.2' diffprog=${DIFFPROG:-'vim -d'} USE_COLOR='y' declare -i USE_FIND=0 +declare DIRECTORY="" declare -a ignored declare -a nontext @@ -101,23 +102,51 @@ version() { cmd() { if (( USE_FIND )); then - find ~/ -name '*sync-conflict*' -print0 + if [[ -z $DIRECTORY ]] + then + # echo "find ~/ -name '*sync-conflict*' -print0" + find ~/ -name '*sync-conflict*' -print0 + else + # echo "find $DIRECTORY -name '*sync-conflict*' -print0" >&2 + find $DIRECTORY -name '*sync-conflict*' -print0 + fi else case "$(uname -s)" in Darwin) - locate -0 sync-conflict;; + locate_cmd=(locate -0);; *) - locate -0 -e -b sync-conflict;; + locate_cmd=(locate -0 -e);; esac + if [[ -z $DIRECTORY ]] + then + locate_opt=(-b) + glob="sync-conflict" + else + locate_opt=(-r) + glob="^${DIRECTORY}.*sync-conflict.*" + fi + # echo "${locate_cmd[@]}" "${locate_opt[@]}" "$glob" >&2 + "${locate_cmd[@]}" "${locate_opt[@]}" "$glob" fi } +check_dir() { + if [[ ! -d $1 ]] + then + echo "Not a directory: $1." + exit 1 + fi + realpath "$1" +} + while [[ -n "$1" ]]; do case "$1" in -h|--help) usage; exit 0;; -v|-V|--version) version; exit 0;; + -d|--directory) + DIRECTORY=$(check_dir "$2"); shift;; -f|--find) USE_FIND=1;; -o|--output)