3 # $0 [server] ([selector]) ([port]) ([mode])
4 # server: the gopher server to dig to
5 # selector: the gopher selector (default is empty)
6 # port: the port to use (default is 70)
7 # mode: the filetype mode (default depends upon selector)
11 # download: fake mode to download the result without changes
14 # LINK_COLOR: escape sequences colour (def: 2)
15 # - : means no escape sequence
26 [ "$PORT" = "" ] && PORT
=70
27 if [ "$MODE" = "" ]; then
28 # "" or dir-like selector? -> 1 ; if not -> 0
29 echo "$SELECTOR" |
grep "/$" >/dev
/null
&& MODE
=1 || MODE
=0
30 [ "$SELECTOR" = "" ] && MODE
=1
33 if [ "$SERVER" = "" ]; then
34 echo "Syntax error: $0 [SERVER] ([SELECTOR]) ([PORT]) ([MODE])" >&2
38 # can be "-" for no escape sequences
39 [ "$LINK_COLOR" = "" ] && LINK_COLOR
=2
41 # Start and end link tags
44 if [ "$LINK_COLOR" != "-" ]; then
45 SL
="`tput setf $LINK_COLOR``tput setaf $LINK_COLOR`"
52 # Display a gopher menu for the given resource
55 cat "$1" |
grep "^i\|^$PREFIX" |
while read ln; do
56 ln="`echo "$ln" | cut -f1`"
57 if echo "$ln" |
grep "^i" >/dev
/null
2>&1; then
58 echo "$ln" |
sed "s:^.: :g"
59 elif echo "$ln" |
grep "^$PREFIX" >/dev
/null
2>&1; then
62 field
="`echo "$ln" | cut -c1`"
65 1) typ
='DIR';; # menu, actually
66 7) typ
='(?)';; # query
67 8) typ
='TEL';; # TELnet (not TELephone)
71 +) typ
='SVR';; # redundant server
74 echo "$ln" |
sed "s:^.\\(.*\\):$typ $i $SL\\1$EL:g"
81 # $0 [FILE] [INDEX] [FIELD]
82 # Get a field from the given-by-index link in FILE
90 cat "$1" |
grep "^$PREFIX" |
tail -n+"$2" |
head -n 1 | cut
-f"$3"
93 tmp
="`mktemp -t gofetch.current_page.XXXXXX`"
99 if [ $MODE = 1 ]; then
100 echo "$SELECTOR" | nc
"$SERVER" "$PORT" |
sed 's:\r::g' > "$tmp"
102 echo "$SELECTOR" | nc
"$SERVER" "$PORT" > "$tmp"
107 # Special, fake mode, only from top-level
115 while [ "$CHOICE" != "" ]; do
116 cat_menu
"$tmp" |
less
117 read -p "[$SELECTOR]: " CHOICE
118 index
="`expr 1 \* "$CHOICE" 2>/dev/null`"
119 if [ "$index" != "" ]; then
120 goto_server
="`getsel "$tmp" $index 3`"
121 goto_sel
="`getsel "$tmp" $index 2`"
122 goto_port
="`getsel "$tmp" $index 4`"
123 goto_mode
="`getsel "$tmp" $index 1 | cut -c1`"
124 sh
"$0" "$goto_server" "$goto_sel" "$goto_port" "$goto_mode"
129 read -p "Query: " SEARCH
130 selQuery
="$SELECTOR $SEARCH"
132 exec sh
"$0" "$SERVER" "$selQuery" "$PORT" 1
135 telnet -l "$SELECTOR" "$SERVER" "$PORT"
139 echo "<BINARY FILE>" |
less
142 echo "unknwon selector mode: <$MODE>" |
less