mirror of
https://github.com/jarun/nnn.git
synced 2025-01-15 13:26:37 +00:00
[kdeconnect] Various improvements (#1551)
- Support multiple devices paired and available at the same time - Filter out non-regular files
This commit is contained in:
parent
2000ed5080
commit
c9b384f009
|
@ -8,7 +8,7 @@
|
||||||
# - Alternatively, select the files and folders you would like to send, and activate the plugin.
|
# - Alternatively, select the files and folders you would like to send, and activate the plugin.
|
||||||
#
|
#
|
||||||
# Shell: POSIX compliant
|
# Shell: POSIX compliant
|
||||||
# Author: juacq97, raffaem
|
# Author: juacq97, raffaem, N-R-K
|
||||||
|
|
||||||
# If you want system notification, put this equal to 1
|
# If you want system notification, put this equal to 1
|
||||||
notify=0
|
notify=0
|
||||||
|
@ -21,17 +21,40 @@ note() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# kdeconnect doesn't cope with non-files
|
||||||
|
filter_files() {
|
||||||
|
xargs -0 -I{} sh -c '
|
||||||
|
if [ -f "{}" ]; then
|
||||||
|
printf "%s\0" "{}";
|
||||||
|
else
|
||||||
|
printf "Error: not a regular file: %s\n" "{}" >&2;
|
||||||
|
fi;'
|
||||||
|
}
|
||||||
|
|
||||||
send() {
|
send() {
|
||||||
xargs -0 -I{} kdeconnect-cli --name "$devname" --share {}
|
filter_files | xargs -0 -I{} kdeconnect-cli --name "$devname" --share {}
|
||||||
note "Files sent"
|
note "Files sent"
|
||||||
}
|
}
|
||||||
|
|
||||||
devname=$(kdeconnect-cli --list-available --name-only 2>/dev/null | awk NR==1)
|
# Select paired device
|
||||||
if [ -z "$devname" ]; then
|
names=$(kdeconnect-cli --list-available --name-only 2>/dev/null)
|
||||||
note "No devices available"
|
if [ -z "$names" ]; then
|
||||||
|
note "No devices paired and available"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
ndevs=$(printf "%s" "$names" | awk 'END{print NR}')
|
||||||
|
if [ "$ndevs" -eq 1 ]; then
|
||||||
|
devname="$names"
|
||||||
|
else
|
||||||
|
printf "%s" "$names" | awk '{ print NR ". " $0 }'
|
||||||
|
printf "Pick a device: "
|
||||||
|
read -r pick
|
||||||
|
if [ -n "$pick" ] && [ "$pick" -eq "$pick" ]; then
|
||||||
|
devname=$(printf '%s' "$names" | awk "NR==$pick")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
||||||
if [ -s "$selection" ]; then
|
if [ -s "$selection" ]; then
|
||||||
send < "$selection"
|
send < "$selection"
|
||||||
|
|
Loading…
Reference in a new issue