Terminal output to seashells via socat

· Robert Guiscard's Blog


seashells provides ways to display terminal output in web browser. But for each command, the url changes. To avoid chainging url, terminal output can first be output to socat as a server, then redirect to seashells.

Here is the command from socat to seashells:

socat -u TCP-LISTEN:12345,keepalive,reuseaddr,fork STDOUT | nc seashells.io 1337

It runs as server and listens to port 12345. And because it is keepalive, the url of seashells whill not change.

To output to this port, try this:

echo "Hello" | socat - TCP-CONNECT:localhost:12345

Or a more complicated version:

ls | tee >(socat - TCP-CONNECT:localhost:12345)

It displays output of ls to seashells via socat.

A very simple bash script generated by AI also works:

#!/bin/bash

PORT=12345

socat_to_port() {
  tee >(socat - TCP-CONNECT:localhost:$PORT)
}

# Parse options before --
while [[ "$#" -gt 0 ]]; do
  case "$1" in
    -p)
      PORT="$2"
      shift 2
      ;;
    --)
      shift
      break
      ;;
    *)
#     not options
      break
      ;;
  esac
done

# Remaining args after -- are the command
cmd=("$@")

# Debug/echo
echo "Using port: $PORT"
echo "+ ${cmd[@]}"

printf "\n\$> $*\n" | socat_to_port
"$@" | socat_to_port

Instead of redirect after the command, this script can run like this run.sh ls -lh. It may be easier to type.