2019-03-25 05:29:37 +00:00
|
|
|
#!/usr/bin/env sh
|
2019-03-17 07:09:15 +00:00
|
|
|
|
2022-12-18 10:39:11 +00:00
|
|
|
# Description: Send files or folders to your Android device using kdeconnect-cli.
|
2021-05-15 17:32:01 +00:00
|
|
|
# kdeconnect must be configured on the Android device and the PC.
|
2019-03-17 07:09:15 +00:00
|
|
|
#
|
2022-12-18 10:39:11 +00:00
|
|
|
# Usage:
|
|
|
|
# - Hover over a file or a folder and call the plugin.
|
|
|
|
# - Alternatively, select the files and folders you would like to send, and activate the plugin.
|
|
|
|
#
|
2019-03-25 05:29:37 +00:00
|
|
|
# Shell: POSIX compliant
|
2023-01-02 16:53:47 +00:00
|
|
|
# Author: juacq97, raffaem, N-R-K
|
2019-03-17 07:09:15 +00:00
|
|
|
|
2022-12-18 10:39:11 +00:00
|
|
|
# If you want system notification, put this equal to 1
|
|
|
|
notify=0
|
2019-04-21 18:29:51 +00:00
|
|
|
|
2022-12-18 10:39:11 +00:00
|
|
|
note() {
|
|
|
|
if [ $notify = 1 ]; then
|
|
|
|
notify-send -a "Kdeconnect" "$1"
|
|
|
|
else
|
|
|
|
echo "[Kdeconnect] $1"
|
|
|
|
fi
|
|
|
|
}
|
2020-12-12 15:23:00 +00:00
|
|
|
|
2023-01-02 16:53:47 +00:00
|
|
|
# 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;'
|
|
|
|
}
|
|
|
|
|
2022-12-18 10:39:11 +00:00
|
|
|
send() {
|
2023-01-02 16:53:47 +00:00
|
|
|
filter_files | xargs -0 -I{} kdeconnect-cli --name "$devname" --share {}
|
2022-12-18 10:39:11 +00:00
|
|
|
note "Files sent"
|
|
|
|
}
|
2021-03-27 11:37:58 +00:00
|
|
|
|
2023-01-02 16:53:47 +00:00
|
|
|
# Select paired device
|
|
|
|
names=$(kdeconnect-cli --list-available --name-only 2>/dev/null)
|
|
|
|
if [ -z "$names" ]; then
|
|
|
|
note "No devices paired and available"
|
2022-12-18 10:39:11 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2023-01-02 16:53:47 +00:00
|
|
|
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
|
|
|
|
|
2022-12-18 10:39:11 +00:00
|
|
|
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
|
|
|
if [ -s "$selection" ]; then
|
|
|
|
send < "$selection"
|
|
|
|
[ -p "$NNN_PIPE" ] && printf "-" > "$NNN_PIPE" # clear selection
|
|
|
|
elif [ -n "$1" ]; then
|
|
|
|
printf "%s" "$1" | send
|
|
|
|
else
|
|
|
|
note "No selection and no hovered file"
|
2019-03-17 07:09:15 +00:00
|
|
|
fi
|