4 # LINK_COLOR: escape sequences colour (def: 2)
5 # - : means no escape sequence
16 [ "$PORT" = "" ] && PORT
=70
17 if [ "$MODE" = "" ]; then
18 # "" or dir-like selector? -> 1 ; if not -> 0
19 echo "$SELECTOR" |
grep "/$" >/dev
/null
&& MODE
=1 || MODE
=0
20 [ "$SELECTOR" = "" ] && MODE
=1
23 if [ "$SERVER" = "" ]; then
24 echo "Syntax error: $0 [SERVER] ([SELECTOR]) ([PORT]) ([MODE])" >&2
28 # can be "-" for no escape sequences
29 [ "$LINK_COLOR" = "" ] && LINK_COLOR
=2
31 # Start and end link tags
34 if [ "$LINK_COLOR" != "-" ]; then
35 SL
="`tput setf $LINK_COLOR``tput setaf $LINK_COLOR`"
40 # Display a gopher menu for the given resource
43 cat "$1" |
grep '^[i0-9]' |
while read ln; do
44 ln="`echo "$ln" | cut -f1`"
45 if echo "$ln" |
grep "^i" >/dev
/null
2>&1; then
46 echo "$ln" |
sed "s:^.: :g"
47 elif echo "$ln" |
grep "^[0-9]" >/dev
/null
2>&1; then
50 field
="`echo "$ln" | cut -c1`"
58 echo "$ln" |
sed "s:^.\\(.*\\):$typ $i $SL\\1$EL:g"
65 # $0 [FILE] [INDEX] [FIELD]
66 # Get a field from the given-by-index link in FILE
74 cat "$1" |
grep '^[0-9]' |
tail -n+"$2" |
head -n 1 | cut
-f"$3"
77 tmp
="`mktemp -t gofetch.current_page.XXXXXX`"
83 if [ $MODE = 1 ]; then
84 echo "$SELECTOR" | nc
"$SERVER" "$PORT" |
sed 's:\r::g' > "$tmp"
86 echo "$SELECTOR" | nc
"$SERVER" "$PORT" > "$tmp"
95 while [ "$CHOICE" != "" ]; do
96 cat_menu
"$tmp" |
less
97 read -p "[$SELECTOR]: " CHOICE
98 index
="`expr 1 \* "$CHOICE" 2>/dev/null`"
99 if [ "$index" != "" ]; then
100 goto_server
="`getsel "$tmp" $index 3`"
101 goto_sel
="`getsel "$tmp" $index 2`"
102 goto_port
="`getsel "$tmp" $index 4`"
103 goto_mode
="`getsel "$tmp" $index 1 | cut -c1`"
104 sh
"$0" "$goto_server" "$goto_sel" "$goto_port" "$goto_mode"
109 read -p "Query: " SEARCH
110 selQuery
="$SELECTOR $SEARCH"
112 exec sh
"$0" "$SERVER" "$selQuery" "$PORT" 1
115 telnet -l "$SELECTOR" "$SERVER" "$PORT"
119 echo "<BINARY FILE>" |
less
122 echo "unknwon selector mode: <$MODE>" |
less