Created
September 8, 2021 22:18
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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