From 58e1b63fb76c82ed4637c877719abd47600bf532 Mon Sep 17 00:00:00 2001 From: fbt Date: Mon, 20 May 2019 15:28:03 +0300 Subject: [PATCH] Support multiple workdirs Signed-off-by: fbt --- ufwd | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ufwd b/ufwd index 5fe469a..d688b96 100755 --- a/ufwd +++ b/ufwd @@ -7,7 +7,6 @@ if ! [[ "$XDG_RUNTIME_DIR" ]]; then fi # Defaults -cfg_workdir="$XDG_RUNTIME_DIR/ufwd" cfg_scan_delay='30' msg() { printf '%s\n' "$*"; } @@ -48,7 +47,8 @@ main() { case "$1" in (--help|-h) usage; return 0;; - (--workdir|-d) cfg_workdir="$2"; shift;; + (--workdir|-d) cfg_workdir+=( "$2" ); shift;; + (--scan-delay|-D) cfg_scan_delay="$2"; shift;; (--notify|-n) flag_enable_notifications=1;; @@ -67,6 +67,8 @@ main() { shift done + [[ $cfg_workdir ]] || cfg_workdir="$XDG_RUNTIME_DIR/ufwd" + if (( flag_enable_notifications )); then if type -P notify-send &>/dev/null; then msg "Found notify-send." @@ -76,12 +78,16 @@ main() { fi fi - mkdir -p "$cfg_workdir" || return 1 - cd "$cfg_workdir" || return 1 + for p in "${cfg_workdir[@]}"; do + [[ -d "$p" ]] || return 1 + done - while read -r dir action path; do - upload "$dir$path" "$@" & - done < <( inotifywait -m -e close_write "$cfg_workdir" ) + printf 'Working in:\n' + printf ' - %s\n' "${cfg_workdir[@]}" + + while read -r d e f; do + upload "$d$f" "$@" & + done < <( inotifywait -m -e close_write "${cfg_workdir[@]}" ) } main "$@"