urlview-factory-url_handler.sh (3067B)
1 #! /bin/bash 2 3 # Copyright (c) 1998 Martin Schulze <joey@debian.org> 4 # Slightly modified by Luis Francisco Gonzalez <luisgh@debian.org> 5 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; either version 2 of the License, or 9 # (at your option) any later version. 10 11 # This program is distributed in the hope that it will be useful, 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 # GNU General Public License for more details. 15 16 # You should have received a copy of the GNU General Public License 17 # along with this program; if not, write to the Free Software 18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 20 ########################################################################### 21 # Configurable section 22 ########################################################################### 23 # 24 # Any entry in the lists of programs that urlview handler will try out will 25 # be made of /path/to/program + ':' + TAG where TAG is one of 26 # XW: XWindows program 27 # XT: Launch with an xterm if possible or as VT if not 28 # VT: Launch in the same terminal 29 30 # The lists of programs to be executed are 31 https_prgs="/usr/X11R6/bin/netscape:XW /usr/bin/lynx:XT" 32 http_prgs="/usr/bin/lynx:XT /usr/X11R6/bin/netscape:XW" 33 mailto_prgs="/usr/bin/mutt:VT /usr/bin/elm:VT /usr/bin/pine:VT /usr/bin/mail:VT" 34 gopher_prgs="/usr/bin/lynx:XT /usr/bin/gopher:XT" 35 ftp_prgs="/usr/bin/lynx:XT /usr/bin/ncftp:XT" 36 37 # Program used as an xterm (if it doesn't support -T you'll need to change 38 # the command line in getprg) 39 XTERM=/usr/X11R6/bin/xterm 40 41 42 ########################################################################### 43 # Change bellow this at your own risk 44 ########################################################################### 45 function getprg() 46 { 47 local ele tag prog 48 49 for ele in $* 50 do 51 tag=${ele##*:} 52 prog=${ele%%:*} 53 if [ -x $prog ]; then 54 case $tag in 55 XW) 56 [ -n "$DISPLAY" ] && echo "X:$prog" && return 0 57 ;; 58 XT) 59 [ -n "$DISPLAY" ] && [ -x "$XTERM" ] && \ 60 echo "X:$XTERM -e $prog" && return 0 61 echo "$prog" && return 0 62 ;; 63 VT) 64 echo "$prog" && return 0 65 ;; 66 esac 67 fi 68 done 69 } 70 71 url="$1"; shift 72 73 type="${url%%:*}" 74 75 if [ "$url" = "$type" ]; then 76 type="${url%%.*}" 77 case "$type" in 78 www|web) 79 type=http 80 ;; 81 esac 82 url="$type://$url" 83 fi 84 85 case $type in 86 https) 87 prg=`getprg $https_prgs` 88 ;; 89 http) 90 prg=`getprg $http_prgs` 91 ;; 92 ftp) 93 prg=`getprg $ftp_prgs` 94 ;; 95 mailto) 96 prg=`getprg $mailto_prgs` 97 url="${url#mailto:}" 98 ;; 99 gopher) 100 prg=`getprg $gopher_prgs` 101 ;; 102 *) 103 echo "Unknown URL type. Please report URL and viewer to:" 104 echo "joey@debian.org." 105 echo -n "Press enter to continue."; read x 106 exit 107 ;; 108 esac 109 110 if [ -n "$prg" ]; then 111 if [ "${prg%:*}" = "X" ]; then 112 ${prg#*:} "$url" 2>/dev/null & 113 else 114 $prg "$url" 115 fi 116 fi 117 118 119 120