# I am the Watcher. I am your guide through this vast new twtiverse.
# 
# Usage:
#     https://watcher.sour.is/api/plain/users              View list of users and latest twt date.
#     https://watcher.sour.is/api/plain/twt                View all twts.
#     https://watcher.sour.is/api/plain/mentions?uri=:uri  View all mentions for uri.
#     https://watcher.sour.is/api/plain/conv/:hash         View all twts for a conversation subject.
# 
# Options:
#     uri     Filter to show a specific users twts.
#     offset  Start index for quey.
#     limit   Count of items to return (going back in time).
# 
# twt range = 1 1
# self = https://watcher.sour.is/conv/jjgaqjq

#!/bin/sh
set -e

svcdir="${svcdir:-$HOME/.svc}"
PATH="$PATH:$svcdir"

[ -d ${svcdir} ] || mkdir -p ${svcdir}
cd ${svcdir} || exit 1

fn_usage() {
    printf "Usage: %s [ -k | -r | -s ] \\n" "$(basename "$0")"
}
if_exec() {
    if ! [ $(stat -l ${2} | awk '{print $1}') = "-rwxr-xr-x" ];then
        printf "%s: %s is not executable \\n" "$(basename "$0")" "$2"
    fi
}
case $1 in
    -k)
        if_exec ${2}
        ${2} ${1}
        ;;
    -r)
        if_exec ${2}
        ${2} ${1}
        ;;
    -s)
        if_exec ${2}
        ${2} ${1}
        ;;
esac