stic/stic
2024-12-12 01:39:10 -06:00

75 lines
1.5 KiB
Bash
Executable file

#!/usr/bin/env sh
usage() {
echo "copy terminfo to a remote host because we're sick of this"
echo
echo "usage: stic [...ssh-args] [-h] term host"
echo
echo "Options:"
echo " --help, -h print this message"
echo
echo "Parameters:"
echo " <term> the name of the terminfo to transfer"
echo " <host> the remote host address"
echo
}
ensure() {
if ! $@ ; then
exit 1
fi
}
# check if any args were passed. if not, display usage information
if [ $# == 0 ] ; then
usage
exit 1;
fi
POSITIONAL_ARGS=()
SSH_ARGS=()
# parse args
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
usage
exit 0
;;
-*|--*)
SSH_ARGS+=("$1")
shift
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameter
# save the term info
TERM="${POSITIONAL_ARGS[0]}"
# ssh connection string
HOST="${POSITIONAL_ARGS[1]}"
# make a temporary file to output the terminfo
TI=`mktemp`
# store the filename without directory for later
FN=$(basename -- "$TI")
# pass -o LogLevel=error to quiet the output on good connections
ARGS="-o LogLevel=error ${SSH_ARGS[*]}"
# output the terminfo
ensure infocmp "$TERM" > "$TI"
# copy the terminfo to the user's home on the remote machine
ensure "scp $ARGS $TI $HOST:"
# ssh into the machine and install the terminfo with tic
sh -c "ssh $ARGS $HOST \"tic -x $FN && rm $FN\""