]> Sergey Matveev's repositories - nnn.git/commitdiff
kdeconnect: misc improvements (#1543)
authorRaffaele Mancuso <54762742+raffaem@users.noreply.github.com>
Sun, 18 Dec 2022 10:39:11 +0000 (11:39 +0100)
committerArun Prakash Jana <engineerarun@gmail.com>
Sun, 18 Dec 2022 15:59:52 +0000 (21:29 +0530)
- Work with multiple connected devices by sending files to the first
  device
- Support multi-files selection
- Support sending hovered file in case no file is selected

Co-authored-by: NRK <nrk@disroot.org>
Co-authored-by: Arun Prakash Jana <engineerarun@gmail.com>
plugins/kdeconnect

index 5f63d8bc8f45f077b344359c581fb17441bd2873..52441d34c369a046854b6ec6dc0c26c6515d3673 100755 (executable)
@@ -1,24 +1,43 @@
 #!/usr/bin/env sh
 
-# Description: Send the selected files to your Android device using kdeconnect-cli.
+# Description: Send files or folders to your Android device using kdeconnect-cli.
 #              kdeconnect must be configured on the Android device and the PC.
 #
+# 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.
+#
 # Shell: POSIX compliant
-# Author: juacq97
+# Author: juacq97, raffaem
 
-selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
+# If you want system notification, put this equal to 1
+notify=0
 
-id=$(kdeconnect-cli -a --id-only | awk '{print $1}')
-if [ -s "$selection" ]; then
-    kdeconnect-cli -d "$id" --share "$(cat "$selection")"
+note() {
+       if [ $notify = 1 ]; then
+               notify-send -a "Kdeconnect" "$1"
+       else
+               echo "[Kdeconnect] $1"
+       fi
+}
 
-    # If you want a system notification, uncomment the next 3 lines.
-    #notify-send -a "Kdeconnect" "Sending $(cat "$selection")"
-#else
-    #notify-send -a "Kdeconnect" "No file selected"
+send() {
+       xargs -0 -I{} kdeconnect-cli --name "$devname" --share {}
+       note "Files sent"
+}
 
-    # Clear selection
-    if [ -p "$NNN_PIPE" ]; then
-        printf "-" > "$NNN_PIPE"
-    fi
+devname=$(kdeconnect-cli --list-available --name-only 2>/dev/null | awk NR==1)
+if [ -z "$devname" ]; then
+       note "No devices available"
+       exit
+fi
+
+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"
 fi