skefir (1166B)
1 #!/usr/bin/env sh 2 3 set -eu 4 5 if [ "$#" -lt 2 ]; then 6 echo "Usage: skefir [-n] <host> <url>" 7 exit 1 8 fi 9 10 if [ "$1" = "-n" ]; then 11 NO_MAP=true 12 shift 13 fi 14 15 link () { 16 LINK=$1 17 LINE=$2 18 ARGS=$3 19 20 printf "[%3d] " "$LINK" 21 echo "$LINE" | awk -F '\t' '{print substr($1, 2)}' 22 23 KEFIR_CALL="$(echo "$LINE" | awk -F '\t' '{printf "%s %s", $3, $2}')" 24 COMMAND="$LINK shell skefir $ARGS $KEFIR_CALL" 25 printf "%s\n" "$COMMAND" >> "$LESSKEY_FILE" 26 } 27 28 viewer () { 29 LINK=1 30 while read -r LINE || [ -n "$LINE" ]; do 31 case "$LINE" in 32 i*) 33 printf " " 34 echo "$LINE" | awk -F '\t' '{print substr($1, 2)}' 35 ;; 36 1*) 37 link "$LINK" "$LINE" "" 38 LINK=$((LINK + 1)) 39 ;; 40 0*) 41 link "$LINK" "$LINE" "-n" 42 LINK=$((LINK + 1)) 43 ;; 44 *) 45 ;; 46 esac 47 done 48 } 49 50 LESSKEY_FILE=$(mktemp -t skefir.XXXXXX) 51 echo "#command" > "$LESSKEY_FILE" 52 53 TEXT=$(printf "%s\r\n" "$2" | nc "$1" 70) 54 [ -z "${NO_MAP:-}" ] && TEXT="$(echo "$TEXT" | viewer)" 55 echo "$TEXT" | less --lesskey-src="$LESSKEY_FILE" 56 57 rm "$LESSKEY_FILE"