+# $0 [gopher uri] ([mode])
+# uri: the gopher URI to dig to, e.g.:
+# - gopher://sdf.org:70/1/faq
+# - sdf.org/faq
+# - sdf.org/1/faq
+# - http://gopher.nikiroo.be:80/news
+# - ...
+# default port is 70 for gopher, 80 for http, 443 for https
+# default filetype depends upon selector:
+# - 0: plain text
+# - 1: menu (dir-like)
+# - ...
+# - download: fake mode to download the result without changes
+
+# Manual:
+# When asked for a number (non-dialog uses only), you can also
+# enter 'n' or 'p' to get the next or previous item (+1 or -1)
+
+# ENV variables:
+# USE_DIALOG: force the usage of the command 'dialog'
+# : true if dialog is found
+# 0 : do not
+# 1 : force the use of dialog
+# LINK_COLOR: escape sequences colour (def: 2)
+# - : means no escape sequence
+# 1 : means colour 1
+# 2 : means colour 2
+# [...]
+# INVERT : invert the output for image viewing (for white backgrounds)
+# 0 : do not invert (default)
+# 1 : invert
+
+# EXIT Codes:
+# 0: ok
+# 1: syntax error
+# 2: cannot contact server
+# 3: unknown selector mode
+# 255: special exit more 'q'
+
+URI="$1"
+
+PREFIX="[0-9hIg+]"
+
+PROTOCOL="`echo $URI | sed 's|^\([^:]*://\)\?\([^:/]*\)\(:[^/]*\)\?/\?\(.*\)\?|\1|g'`"
+SERVER="`echo $URI | sed 's|^\([^:]*://\)\?\([^:/]*\)\(:[^/]*\)\?/\?\(.*\)\?|\2|g'`"
+PORT="`echo $URI | sed 's|^\([^:]*://\)\?\([^:/]*\)\(:[^/]*\)\?/\?\(.*\)\?|\3|g'`"
+SELECTOR="`echo $URI | sed 's|^\([^:]*://\)\?\([^:/]*\)\(:[^/]*\)\?/\?\(.*\)\?|\4|g'`"
+MODE=
+
+PORT="`echo "$PORT" | sed 's/^://'`"