aboutsummaryrefslogtreecommitdiffstats
path: root/.config/init/funcs/send
blob: 88b3dbb9e66b643f74687e0525510485d6ac1d0c (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
48
#!/bin/zsh
# quickly send a file to hosted tmp dir

local name
local basename
local escapes
typeset -A escapes
escapes=(' ' '%20' '"' '%22' '#' '%23' '$' '%24'
		 '%' '%25' '&' '%26' "'" '%27' '+' '%2b'
		 ',' '%2c' '/' '%2f' ':' '%3a' ';' '%3b'
		 '<' '%3c' '=' '%3d' '>' '%3e' '?' '%3f'
		 '@' '%40' '[' '%5b' '\' '%5c' ']' '%5d'
		 '^' '%5e' '`' '%60' '{' '%7b' '|' '%7c'
		 '}' '%7d' '~' '%7e')
if [[ "$1" ]]; then
	for i in "$@"; do
		[[ -f "$i" ]] \
			|| { echo "file '$i' not found"; return 1 }
	done
	scp "$@" shmibbles.me:http/tmp/ >/dev/null 2>&1 \
		|| { echo "sending files failed"; return 1 }
	if [[ $? -eq 0 ]]; then
		for name in "$@"
		do
			basename=${name:t}
			ssh shmibbles.me "cd http/tmp; chmod o+r \"${basename//\"/\\\"}\""
			if [[ $? -eq 0 ]]; then
				{
					printf "%s" 'https://shmibbles.me/tmp/'
					for c in "${(s::)basename}"; do 
						if [[ "${escapes[$c]}" == "" ]]; then
							printf "%s" "$c"
						else
							printf "%s" "${escapes[$c]}"
						fi
					done
				} | tee >(xclip -i -selection clipboard) \
					| xclip -i -selection primary
			else
				echo "making '$name' readable failed"
				return 1
			fi
		done
	fi
else
	echo "specify at least one file to send"
	return 1
fi