mirror of
https://github.com/rwxrob/dot
synced 2024-11-18 15:25:52 +00:00
57 lines
1.2 KiB
Bash
Executable File
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
|