File: url_handler.sh

package info (click to toggle)
tin 1%3A2.6.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,368 kB
  • sloc: ansic: 94,105; sh: 4,281; makefile: 1,233; perl: 1,157; yacc: 734
file content (71 lines) | stat: -rwxr-xr-x 1,697 bytes parent folder | download | duplicates (2)
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
60
61
62
63
64
65
66
67
68
69
70
71
#! /bin/sh
#
# example of how to call the appropriate viewer
# based on a script by Michael Elkins <me@cs.hmc.edu>
# 2001-01-31 <urs@tin.org>
#
# URLs must start with a scheme and shell metas must be already quoted
# (tin doesn't recognize URLs without a scheme and it quotes the metas)
#
# TODO: check $BROWSER?

if test $# -ne 1; then
	echo "Usage: `basename "$0"` URL" >&2
	exit 1
fi

url="$1"
method=`echo "$url" | sed 's,^\([^:]*\):.*,\1,' | tr 'A-Z' 'a-z'`

case "$method" in
	http|https|gopher)
		if test x"$DISPLAY" = x; then
			lynx "$url" || exit 1
		else
			( netscape -remote openURL\("$url"\) || netscape "$url" ) || exit 1
		fi
		;;

	ftp)
		if test x"$DISPLAY" = x; then
			target=`echo "$url" | sed 's;^.*://\([^/]*\)/*\(.*\);\1:/\2;'`
			( ncftp "$target" || ncftp "$target""/" ) || exit 1
		else
			( netscape -remote openURL\("$url"\) || netscape "$url" ) || exit 1
		fi
		;;

	mailto)
		( mutt "$url" ) || exit 1
		# ( pine -url "$url" ) || exit 1
#		# old mutts can't handle mailto:-URLs with embedet subject
#		if test `echo "$url" | grep -c '\?'` -eq 0 ; then
#			( mutt `echo "$url" | sed 's;^[^:]*:\(.*\);\1;'` ) || exit 1
#		else
#			if test x"$DISPLAY" = x; then
#				lynx "$url" || exit 1
#			else
#				( netscape -remote openURL\("$url"\) || netscape "$url" ) || exit 1
#			fi
#		fi
		;;

	news|snews)
		# usually meant for reading news on the local server
		if test x"$DISPLAY" = x; then
			lynx "$url" || exit 1
		else
			( netscape -remote openURL\("$url"\) || netscape "$url" ) || exit 1
		fi
		;;

	nntp)
		# usually meant for reading news via NNTP
		# needs a special case as netscape can't handle nntp-URLs
		# *sigh*
		lynx "$url" || exit 1
		;;

esac

exit 0