summaryrefslogtreecommitdiff
path: root/.local/bin/fsend
blob: f75739d7e7589be0d950726975eba0410ee94a33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh

content="${1:-$(xprint | fzf -m --header "Select clipboard lines to send")}" || exit
host="${2:-$(sed '/^Host \(.*\)/!d; s//\1/' ~/.ssh/config | fzf --header "Send to?")}" || exit
sshadd "$(find ~/.ssh -name "${host}_id_*" | head -1)"
[ -z "$NOTIFY" ] && command -V notify-send >/dev/null && NOTIFY=1

notify() {
	[ "$NOTIFY" = 1 ] && notify-send -r 8529 "$@"
	printf "%s\n" "$@"
}

transferto() {
	notify "Transfering files to $host:$1/" "$content"
	rsync -PLru --progress "$content" "$host:$1/"
}

if [ -e "$content" ]; then
	case "$content" in
		*.txt|*.pdf) transferto "Documents" ;;
		*)
			case "$(file --brief --mime-type "$content")" in
				text/*) transferto "Documents" ;;
				image/*) transferto "Pictures" ;;
				audio/*) transferto "Music" ;;
				video/*) transferto "Videos" ;;
				*) transferto "Downloads" ;;
			esac
			;;
	esac

else
	case "$content" in
		http*) notify "Opening link in $host" "$content"
			ssh "$host" "xdg-open \"$content\"" ;;
		*) notify "Copying in $host's clipboard" "$content"
			ssh "$host" "termux-clipboard-set \"$content\"" ;;
	esac
fi

if [ $? = 0 ]; then
	notify "  Done (fzf-send)"
else
	notify " ❌ Errors Occured (fzf-send)"
	printf "\n%s" "Press Enter to continue..."
	read -r
fi