9 Commits

Author SHA1 Message Date
fbt
47fe62a7c8 duh
Signed-off-by: fbt <fbt@fleshless.org>
2019-06-03 02:21:56 +03:00
fbt
639a97f43e I SAID NO MORE
Signed-off-by: fbt <fbt@fleshless.org>
2019-05-20 15:31:06 +03:00
fbt
784ad95215 There is no scan anymore
Signed-off-by: fbt <fbt@fleshless.org>
2019-05-20 15:30:35 +03:00
fbt
58e1b63fb7 Support multiple workdirs
Signed-off-by: fbt <fbt@fleshless.org>
2019-05-20 15:28:03 +03:00
fbt
65fdd688bf That was poorly researched
Signed-off-by: fbt <fbt@fleshless.org>
2019-05-13 22:57:40 +03:00
fbt
488fdc0a5a oops-driven development
Signed-off-by: fbt <fbt@fleshless.org>
2019-05-10 00:18:29 +03:00
fbt
14af6b720f oops
Signed-off-by: fbt <fbt@fleshless.org>
2019-05-09 23:55:03 +03:00
fbt
c22e34afb2 aaaand fork for every file
Signed-off-by: fbt <fbt@fleshless.org>
2019-05-09 23:50:33 +03:00
fbt
d7f1104f82 use inotifywait; clipboard
Signed-off-by: fbt <fbt@fleshless.org>
2019-05-09 23:31:25 +03:00
2 changed files with 49 additions and 40 deletions

14
ufw
View File

@@ -388,8 +388,18 @@ main() {
done done
case "${action:-upload}" in case "${action:-upload}" in
upload) upload "$1";; upload)
url) get_shortlink "$1";; for t in "$@"; do
upload "$t"
done
;;
url)
for t in "$@"; do
get_shortlink "$1"
done
;;
getmyip) get_my_ip;; getmyip) get_my_ip;;
login) login;; login) login;;
esac esac

91
ufwd
View File

@@ -6,10 +6,6 @@ if ! [[ "$XDG_RUNTIME_DIR" ]]; then
XDG_RUNTIME_DIR="/run/user/$UID" XDG_RUNTIME_DIR="/run/user/$UID"
fi fi
# Defaults
cfg_workdir="$XDG_RUNTIME_DIR/ufwd"
cfg_scan_delay='30'
msg() { printf '%s\n' "$*"; } msg() { printf '%s\n' "$*"; }
err() { echo "$*" >&2; } err() { echo "$*" >&2; }
@@ -18,51 +14,12 @@ usage() {
printf ' -h # Show this message.\n' printf ' -h # Show this message.\n'
printf ' -n # Enable notifications with notify-send. Must be installed.\n' printf ' -n # Enable notifications with notify-send. Must be installed.\n'
printf ' -d [path] # Set the dir that is to be watched.\n' printf ' -d [path] # Set the dir that is to be watched.\n'
printf ' -D [sec] # Set the check interval.\n'
} }
main() { upload() {
while (( $# )); do declare file=$1; shift
case "$1" in
(--help|-h) usage; return 0;;
(--workdir|-d) cfg_workdir="$2"; shift;; upload_output=$( ufw -R "$@" "$file" )
(--scan-delay|-D) cfg_scan_delay="$2"; shift;;
(--notify|-n) flag_enable_notifications=1;;
(--) shift; break;;
(-*)
err "Unknown key: $1"
usage
return 1
;;
(*) break;;
esac
shift
done
if (( flag_enable_notifications )); then
if type -P notify-send &>/dev/null; then
msg "Found notify-send."
else
err "notify-send not found in PATH, disabling notifications."
flag_enable_notifications=0
fi
fi
mkdir -p "$cfg_workdir" || {
return 1
}
cd "$cfg_workdir" || {
return 1
}
while sleep "$cfg_scan_delay"; do
for i in *; do
upload_output=$( ufw "$@" -R "$i" )
upload_return=$? upload_return=$?
if (( flag_enable_notifications )); then if (( flag_enable_notifications )); then
@@ -73,9 +30,51 @@ main() {
fi fi
fi fi
if (( flag_enable_clipboard )); then
read -r fl <<< "$upload_output"
xclip <<< "$fl"
fi
printf '%s\n' "$upload_output" printf '%s\n' "$upload_output"
}
main() {
while (( $# )); do
case "$1" in
(--help|-h) usage; return 0;;
(--notify|-n) flag_enable_notifications=1;;
(--clipboard|-c) flag_enable_clipboard=1;;
(--workdir|-d) cfg_workdir+=( "$2" ); shift;;
(--) shift; break;;
(-*) err "Unknown key: $1"; usage; return 1;;
(*) break;;
esac
shift
done 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."
else
err "notify-send not found in PATH, disabling notifications."
flag_enable_notifications=0
fi
fi
for p in "${cfg_workdir[@]}"; do
[[ -d "$p" ]] || return 1
done done
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 "$@" main "$@"