Support multiple workdirs

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2019-05-20 15:28:03 +03:00
parent 65fdd688bf
commit 58e1b63fb7

20
ufwd
View File

@ -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 "$@"