Skip to content

Instantly share code, notes, and snippets.

@kousu
Last active March 26, 2021 19:50
Show Gist options
  • Save kousu/855c164979af078f623fd44f0e1b5350 to your computer and use it in GitHub Desktop.
Save kousu/855c164979af078f623fd44f0e1b5350 to your computer and use it in GitHub Desktop.
showterm.io sh client, with https://github.com/ConradIrwin/showterm/issues/48 applied

showterm.io

Installation:

mkdir -p ~/.local/bin
curl https://gist.githubusercontent.com/kousu/855c164979af078f623fd44f0e1b5350/raw/6536924551c9de7143492c407f4e584389ba3f9f/showterm > .local/bin/showterm
chmod +x .local/bin/showterm

🏚️Depending on your OS, you may or may not have ~/.local/bin setup. If not, do:

tee -a ~/.profile <<EOF

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
   PATH="$HOME/.local/bin:$PATH"
fi

EOF

And re-login.

Usage

$ ./showterm 
showterm recording. (Exit shell when done.)
$ run-some-scripts
bash: run-some-scripts: command not found
$ do-some-stuff
bash: do-some-stuff: command not found
$ exit
exit
Uploading...
https://showterm.io/201731a2361a397828528
#!/bin/bash
# A simple Linux-only pure-shell showterm client for those without Ruby.
#
# Mac users (and Linux users with Ruby installed) should use the ruby client:
# (sudo) gem install showterm
#
# Dependencies (please let me know if you don't have them all already)
# mktemp (coreutils)
# script (util-linux)
# tput (ncurses)
# bash
# curl
#
# To install. Just copy this file to your computer, and chmod +x showterm.
#
# curl showterm.io/showterm > ~/bin/showterm
# chmod +x ~/bin/showterm
#
# Otherwise you can run this file without installing:
#
# bash <(curl record.showterm.io)
#
set -e
record_base_url="https://showterm.io/record"
upload_base_url="https://showterm.io"
if ! tty >/dev/null
then
echo "Usage: bash <(curl $record_base_url)"
exit 1
fi
if [ "-d" = "$1" -o "--delete" = "$1" ]
then
url="${2?-Usage showterm --delete }"
curl --fail "$url" -X "DELETE" --data-urlencode "secret@$HOME/.showterm"
exit
fi
scriptfile="$(mktemp /tmp/XXXXX.script)"
timingfile="$(mktemp /tmp/XXXXX.timing)"
cols="$(tput cols)"
lines="$(tput lines)"
server="${SHOWTERM_SERVER-$upload_base_url}"
url="${server%/}/scripts"
if [ "$*" ]
then
echo "$*"
args=-c "$*"
fi
if [ ! -f "$HOME/.showterm" ]
then
echo -n $(openssl rand -hex 16) > "$HOME/.showterm"
fi
echo "showterm recording. (Exit shell when done.)"
script $args -q -t"$timingfile" "$scriptfile"
echo "Uploading..."
if curl --fail "$url" --data-urlencode "cols=$cols" --data-urlencode "lines=$lines" --data-urlencode "scriptfile@$scriptfile" --data-urlencode "timingfile@$timingfile" --data-urlencode "secret@$HOME/.showterm"
then
echo ""
rm "$scriptfile" "$timingfile"
exit 0
else
echo "Uploading failed, but don't worry! Your work is safe. You can try uploading again with:"
echo curl "$url" --data-urlencode "cols=$cols" --data-urlencode "lines=$lines" --data-urlencode "scriptfile@$scriptfile" --data-urlencode "timingfile@$timingfile" --data-urlencode "secret@$HOME/.showterm"
fi
@kousu
Copy link
Author

kousu commented Mar 26, 2021

Apparently this is only necessary so far for Linux. macOS and probably Ubuntu still have an older curl that is still compatible with the older version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment