xrsh/xrsh
Leon van Kammen e3903e3beb
Some checks failed
/ mirror_to_github (push) Failing after 1m57s
/ test (push) Successful in 8s
remote keyboard improvements + docs
2025-02-14 17:19:04 +01:00

42 lines
1.2 KiB
Bash
Executable file

#!/bin/sh
PORT=9090
PROCFILE=/tmp/.xrsh
usage(){ echo "Usage: xrsh [--keyboard] [--kill]"; exit; }
assert_cmds(){
for cmd in $1; do
command -v $cmd &>/dev/null || { echo "error: please install $cmd (not found)"; exit 1; }
done
}
showip(){
{ # naive way of getting network ip
command -v ip &>/dev/null && ip addr show
command -v ifconfig &>/dev/null && ifconfig
} | grep 'inet ' | grep -v ' 127' | awk '! /addr:/ { gsub(/\/.*/,"",$2); if( !SEEN[$2] ) print $2; SEEN[$2]=1 }'
}
keyboard(){
assert_cmds websocat pkill
trap "stty sane; trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT # cleanup processes when exit
echo $$ > $PROCFILE
echo ""
echo " 1. type 'k' (remote keyboard) in xrsh"
echo " 2. enter ipaddress: $(showip)"
echo ""
echo "warn: CTRL-C is forwarded too"
echo "warn: to exit this app run: $0 --kill"
echo "warn: this terminal is now in raw sendmode, expect weird characters!"
stty raw
websocat -E -b -s 0.0.0.0:$PORT 2>&1
}
# launch!
test -n "$1" || { echo "usage: xrsh [--keyboard] [--kill]"; exit; }
case "$*" in
--kill) pkill -P $(cat $PROCFILE); exit ;;
--keyboard) keyboard ;;
esac