summaryrefslogtreecommitdiff
path: root/bin/guiscripts/stplumb
blob: 1898bd168ba9dfbbf1c9948aac968c689bd8eace (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
#!/bin/sh

select_link() {
	regex='(((file|https?|gopher|gemini|ftps?|git)://|www\.)[a-zA-Z0-9.]*[:;!a-zA-Z0-9./+@$&%?$\#=_~-]*)|(magnet:\?xt=urn:btih:[a-zA-Z0-9]*)'
	tr -d '\n' | grep -Eo "$regex" | dmenu -n -x -c
}

case $1 in
'copylink')
	url="$(select_link)"
	[ "$url" ] || exit 1
	printf '%s' "$url" | clipp
	;;
'open')
	url="$(select_link)"
	[ "$url" ] || exit 1
	lh "$url"
	;;
'copypath')
	path="$(grep -Eo -e '/([^/ ](/?)+)+' -e '[^ /]+/+([^ /]+(/?)+)*' |
		sort | uniq | dmenu -n -x -c)"
	[ "$path" ] || exit 1
	printf '%s' "$path" | clipp
	;;
*)
	echo "no option"
	exit 1
	;;
esac