commit 46c5b5bcadd6f5ce7d7ab1ae717a6d67f865a22d Author: kitsunecafe Date: Thu Dec 12 01:39:10 2024 -0600 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..935b611 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# stic +i got sick of manually transferring terminfo files + +# Usage + +```bash +stic terminfo-name remote-host [...ssh-args] +``` + +# Example +```bash +stic alacritty cute.fox -p 2222 +``` + diff --git a/stic b/stic new file mode 100755 index 0000000..936d283 --- /dev/null +++ b/stic @@ -0,0 +1,75 @@ +#!/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 " the name of the terminfo to transfer" + echo " 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\"" +