X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=gopher.sh;h=0042756538be4be9758e701ce79fe04c462b2b0a;hb=c6852b70b860baecf8efa526631f6ec42f0a693e;hp=f91be7a8c6f27fa1a30be4086280f1fab2a0538b;hpb=0eb21b2178dbb2cc1faea64447b861a91e442b90;p=gofetch.git diff --git a/gopher.sh b/gopher.sh index f91be7a..0042756 100755 --- a/gopher.sh +++ b/gopher.sh @@ -1,5 +1,12 @@ #!/bin/sh +# ENV variables: +# LINK_COLOR: escape sequences colour (def: 2) +# - : means no escape sequence +# 1 : means colour 1 +# 2 : means colour 2 +# [...] + SERVER="$1" SELECTOR="$2" PORT="$3" @@ -18,7 +25,19 @@ if [ "$SERVER" = "" ]; then exit 2 fi +# can be "-" for no escape sequences +[ "$LINK_COLOR" = "" ] && LINK_COLOR=2 + +# Start and end link tags +SL= +EL= +if [ "$LINK_COLOR" != "-" ]; then + SL="`tput setf $LINK_COLOR``tput setaf $LINK_COLOR`" + EL="`tput init`"; +fi + # $0 [FILE] +# Display a gopher menu for the given resource cat_menu() { i=0 cat "$1" | grep '^[i0-9]' | while read ln; do @@ -32,29 +51,20 @@ cat_menu() { case "$field" in 0) typ='TXT';; 1) typ='DIR';; - 7) typ='SRH';; + 7) typ='(?)';; 8) typ='TEL';; - *) typ='???';; + *) typ='!!!';; esac - echo "$ln" | sed "s:^.:$typ $i :g" + echo "$ln" | sed "s:^.\\(.*\\):$typ $i $SL\\1$EL:g" #else # Bad line fi done } -# $0 [FILE] -choices() { - i=0 - cat "$1" | grep '^[0-9]' | while read choice; do - i=`expr $i + 1` - i=`printf %2.f $i` - - echo "$i --> $choice" - done -} - # $0 [FILE] [INDEX] [FIELD] +# Get a field from the given-by-index link in FILE +# # Fields: # 1 = type/name # 2 = selector @@ -64,7 +74,7 @@ getsel() { cat "$1" | grep '^[0-9]' | tail -n+"$2" | head -n 1 | cut -f"$3" } -tmp="`mktemp gofetch.current_page.XXXXX`" +tmp="`mktemp -t gofetch.current_page.XXXXXX`" finish() { rm -rf "$tmp" }