Skip to content

Instantly share code, notes, and snippets.

@gma
Created September 8, 2021 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gma/b2e55410f2e1001012d4439985559955 to your computer and use it in GitHub Desktop.
Save gma/b2e55410f2e1001012d4439985559955 to your computer and use it in GitHub Desktop.
Script that hits cht.sh with query, results in a new tmux window
#!/bin/bash
## Functions
usage()
{
echo "Usage: $(basename $0) <arg> [args...]" 1>&2
exit 1
}
join_by()
{
local IFS="$1"
shift
echo "$*"
}
## Main program
SLUG="$1"
[ -z "$SLUG" ] && usage
shift
URL="https://cht.sh/$SLUG"
if [ -n "$1" ]; then
URL="$URL/$(join_by '+' $@)"
fi
COMMAND="curl -s $URL | less -R"
if [ -n "$TMUX" ]; then
tmux new-window -n cht.sh "$COMMAND"
else
bash -c "$COMMAND"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment