~mil/sxmo-utils

ref: dbc3b1ab509aab5f1db72c5cece2ee2a6eb521e8 sxmo-utils/scripts/core/sxmo_urlhandler.sh -rwxr-xr-x 1.8 KiB
dbc3b1abStacy Harper Allow the sendnewtextmenu to be used with a number as arg 1 year, 4 months ago
                                                                                
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
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env sh

# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"

FORK="$2"

if [ -n "$1" ]
then
	# E.g. passed liked: sxmo_urlhandler.sh http://foo.com
	URL="$1"
else
	# Surf
	WINDOW="$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')"
	SURFURL="$(xprop -id "$WINDOW" | grep URI | awk '{print $3}' | sed 's/\"//g')"
	if [ -n "$SURFURL" ]; then
		URL="$SURFURL"
	fi

	# Is normal browser? (FF or Netsurf) - use Ctrl-L Ctrl-C to copy URL
	ISNORMBROWS="$(xprop -id "$(xdotool getactivewindow)" | grep -E 'WM_CLASS.*(Netsurf|Firefox)')"
	if [ -n "$ISNORMBROWS" ]; then
		xdotool key --clearmodifiers --delay 20 "ctrl+l" "ctrl+c"
		sleep 0.2
		URL="$(xclip -o)"
	fi
fi

COMMAND=$(
	echo "
		Close Menu
		$(command -v w3m        >/dev/null && echo 'w3m URL')
		$(command -v mpv        >/dev/null && echo 'mpv -ao=alsa -v URL')
		$(command -v mpv        >/dev/null && echo 'mpv -ao=alsa -v --ytdl-format="[height<420]" URL')
		$(command -v firefox    >/dev/null && echo 'firefox -new-window URL')
		$(command -v netsurf    >/dev/null && echo 'netsurf URL')
		$(command -v surf       >/dev/null && echo 'surf URL')
		$(command -v echo       >/dev/null && echo 'echo URL | xsel -i')
		$(command -v youtube-dl >/dev/null && echo 'youtube-dl -o- URL | mpv -ao=alsa -v -')
		$(command -v youtube-dl >/dev/null && echo 'youtube-dl URL')
		$(command -v curl       >/dev/null && echo 'curl URL | vis -')
		$(command -v wget       >/dev/null && echo 'wget URL')
		$(command -v aria2c     >/dev/null && echo 'aria2c URL')
	" |
		sed "s/URL/'URL'/g" |
		sed -e '/^\s*$/d' |
		sed -e 's/^\s*//' |
		dmenu -p "Pipe URL" -c -l 20
)

[ "$COMMAND" = "Close Menu" ] && exit 1
[ -z "$COMMAND" ] && exit 1
RUN=$(echo "$URL" | xargs -IURL echo "$COMMAND")
if [ "$FORK" = fork ]; then
	st -e sh -c "$RUN" &
else
	st -e sh -c "$RUN"
fi