added send to device shell script. master
authordanix <danix@danix.xyz>
Tue, 21 Mar 2023 17:15:34 +0000 (18:15 +0100)
committerdanix <danix@danix.xyz>
Tue, 21 Mar 2023 17:15:34 +0000 (18:15 +0100)
bin/send-to-device.sh [new file with mode: 0755]

diff --git a/bin/send-to-device.sh b/bin/send-to-device.sh
new file mode 100755 (executable)
index 0000000..a320e0f
--- /dev/null
@@ -0,0 +1,54 @@
+#! /bin/bash
+
+QARMA="/usr/bin/qarma"
+KDECONN=$(which kdeconnect-cli)
+CHOICE=/tmp/choose_devices
+OUTPUT=/tmp/share_output
+
+
+function scan_devices() {
+       if [[ -f $CHOICE ]]; then
+               rm $CHOICE
+       fi
+       DEV_NAMES=$(${KDECONN} -a --name-only)
+       DEV=$($QARMA --list --text="Select your device" --hide-header "$DEV_NAMES" > $CHOICE)
+       case $? in
+               0 )
+                       # echo "${KDECONN} --share figa -n \"$(cat $CHOICE)\""
+                       DEVICE="$(cat $CHOICE)"
+                       ;;
+               1 )
+                       $QARMA --info --title="Exiting!" --text="No device was selected."
+                       DEVICE=""
+                       ;;
+               -1 )
+                       $QARMA --error --title="Ooops!!" --text="Something unexpected happened."
+                       DEVICE=""
+                       ;;
+       esac
+       printf %s "$DEVICE"
+}
+
+function send_file() {
+       if [[ -f $OUTPUT ]]; then
+               rm $OUTPUT
+       fi
+       if [[ -f $1 && -n $2 ]]; then
+               FILE=$1
+               DEST=$2
+               echo -e "Sharing to ${DEST} - " > $OUTPUT
+               $KDECONN --share "$FILE" -n "$DEST" 2>&1 >> $OUTPUT
+               $QARMA --info --title="Share to Device" --text="$(cat $OUTPUT)"
+       else
+               echo "no device selected"
+       fi
+}
+
+if [[ -f $1 ]]; then
+       # we have a file to share
+       SHARED=$1
+       SHAREDTO=$(scan_devices)
+       send_file "$SHARED" "$SHAREDTO"
+else
+       echo "tell me what to send"
+fi