sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

kdeconnect (1638B)


      1 #!/usr/bin/env sh
      2 
      3 # Description: Send files or folders to your Android device using kdeconnect-cli.
      4 #              kdeconnect must be configured on the Android device and the PC.
      5 #
      6 # Usage:
      7 #   - Hover over a file or a folder and call the plugin.
      8 #   - Alternatively, select the files and folders you would like to send, and activate the plugin.
      9 #
     10 # Shell: POSIX compliant
     11 # Author: juacq97, raffaem, N-R-K
     12 
     13 # If you want system notification, put this equal to 1
     14 notify=0
     15 
     16 note() {
     17 	if [ $notify = 1 ]; then
     18 		notify-send -a "Kdeconnect" "$1"
     19 	else
     20 		echo "[Kdeconnect] $1"
     21 	fi
     22 }
     23 
     24 # kdeconnect doesn't cope with non-files
     25 filter_files() {
     26 	xargs -0 -I{} sh -c '
     27 		if [ -f "{}" ]; then
     28 			printf "%s\0" "{}";
     29 		else
     30 			printf "Error: not a regular file: %s\n" "{}" >&2;
     31 		fi;'
     32 }
     33 
     34 send() {
     35 	filter_files | xargs -0 -I{} kdeconnect-cli --name "$devname" --share {}
     36 	note "Files sent"
     37 }
     38 
     39 # Select paired device
     40 names=$(kdeconnect-cli --list-available --name-only 2>/dev/null)
     41 if [ -z "$names" ]; then
     42 	note "No devices paired and available"
     43 	exit
     44 fi
     45 
     46 ndevs=$(printf "%s" "$names" | awk 'END{print NR}')
     47 if [ "$ndevs" -eq 1 ]; then
     48 	devname="$names"
     49 else
     50 	printf "%s" "$names" | awk '{ print NR ". " $0 }'
     51 	printf "Pick a device: "
     52 	read -r pick
     53 	if [ -n "$pick" ] && [ "$pick" -eq "$pick" ]; then
     54 		devname=$(printf '%s' "$names" | awk "NR==$pick")
     55 	fi
     56 fi
     57 
     58 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
     59 if [ -s "$selection" ]; then
     60 	send < "$selection"
     61 	[ -p "$NNN_PIPE" ] && printf "-" > "$NNN_PIPE" # clear selection
     62 elif [ -n "$1" ]; then
     63 	printf "%s" "$1" | send
     64 else
     65 	note "No selection and no hovered file"
     66 fi