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