rwxrob-dot/scripts/twitter
Rob Muhlestein 2ea0289e9f Rebase
2022-02-09 02:29:05 -05:00

57 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/bash
USER=rwxrob
EMAIL=rob@rwx.gg
ID=1210114652
update () {
local status="$1" image="$2" data media_id
if [[ -n "${image}" ]]; then
media_id=$(twurl -X POST -H upload.twitter.com \
'/1.1/media/upload.json?media_category=TWEET_IMAGE&additional_owners='${ID} \
-f "${image}" -F media | jq .media_id )
data="media_ids=${media_id}&status=${status}"
echo "$data"
else
data="status=${status}"
fi
twurl '/1.1/statuses/update.json' -d "${data}" | jq .created_at
}
tweets () {
twurl "/2/tweets?ids=$1"
}
############################## Main Command #############################
subcommand="${1-usage}"
shift 2>/dev/null
if [ -z "$subcommand" ]; then
usage
exit 1
fi
commands () {
echo ${commands[@]}
}
declare -a commands=(commands update tweets)
for i in ${commands[@]}; do
if [[ "$i" == "$subcommand" ]]; then
"$subcommand" "$@"
exit 0
fi
done
######################### Tab Completion Context ########################
# remember COMP_LINE is changed by shift
if [ -n "$COMP_LINE" ]; then
for cmd in ${commands[@]}; do
[[ "${cmd:0:${#1}}" == "$1" ]] && echo $cmd
done
exit 0
fi