Skip to content

Instantly share code, notes, and snippets.

@benaryorg
Last active August 29, 2023 22:19
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 benaryorg/1394046d2173f20bebbbe0dbd1005410 to your computer and use it in GitHub Desktop.
Save benaryorg/1394046d2173f20bebbbe0dbd1005410 to your computer and use it in GitHub Desktop.
pishock shocking CLI for zsh
#!/usr/bin/env zsh
set -e
usage() {
cat <<END
Usage: $0 [-v] [-i INTENSITY] [-d DURATION]
Uses configuration files in XDG directories to shock using the pishock API.
Create a symlink to this file called "user-shock" where "user" is a name you choose.
You can the put the files "user", "code", and "apikey" in the directory in your XDG config directory.
e.g. ~/.config/pishock/\${user}/{user,apikey,code}
-v only vibrate
-i intensity
-i duration
-h print help
END
}
param_op=0
param_intensity=1
param_duration=1
cmd=${0##*/}
profile=${cmd%-shock}
config=${XDG_CONFIG_HOME:-~/.config}/pishock/$profile
read -r cfg_user < $config/user
read -r cfg_code < $config/code
read -r cfg_apikey < $config/apikey
while getopts "hvi:d:" o; do
case "$o" in
v)
param_op=1
;;
d)
param_duration=$OPTARG
;;
i)
param_intensity=$OPTARG
;;
h)
usage
exit 0
;;
*)
usage >&2
exit 1
;;
esac
done
shift $(( OPTIND - 1 ))
if (( $# > 0 ));then
usage >&2
exit 1
fi
jq -n \
--arg Username $cfg_user \
--arg Name $USER \
--arg Code $cfg_code \
--arg Intensity $param_intensity \
--arg Duration $param_duration \
--arg Apikey $cfg_apikey \
--arg Op $param_op \
'{$Username, $Name, $Code, $Intensity, $Duration, $Apikey, $Op}' \
| curl -s -d @- -H "accept: application/json" -H "content-type: application/json" https://do.pishock.com/api/apioperate \
| jq -r .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment