From: danix Date: Tue, 21 Mar 2023 17:15:34 +0000 (+0100) Subject: added send to device shell script. X-Git-Url: https://git.danix.xyz/?p=my-dotfiles.git;a=commitdiff_plain;h=HEAD added send to device shell script. --- diff --git a/bin/send-to-device.sh b/bin/send-to-device.sh new file mode 100755 index 0000000..a320e0f --- /dev/null +++ b/bin/send-to-device.sh @@ -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