2021-07-04 17:42:20 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Query local syncthing REST API
|
2021-07-25 21:51:56 +00:00
|
|
|
test $# -eq 0 && echo "Usage: st <command> [args...]" && exit 1
|
2021-07-04 17:42:20 +00:00
|
|
|
subscript="$(which "$(basename $0)-$1" 2>/dev/null)"
|
|
|
|
if test -f "$subscript"
|
|
|
|
then shift && $subscript "$@"
|
|
|
|
else
|
|
|
|
apikey=$(grep apikey $XDG_CONFIG_HOME/syncthing/config.xml | cut -d '>' -f2 | cut -d '<' -f1)
|
|
|
|
case "$1" in
|
2021-07-04 19:56:12 +00:00
|
|
|
(browse|completion|file|ignores|need|status)
|
2021-07-04 17:42:20 +00:00
|
|
|
for arg in "${@:2}"
|
|
|
|
do case "$arg" in ([0-9]) depth=$arg;; (*) path="$arg";; esac
|
|
|
|
done
|
2021-07-04 21:22:53 +00:00
|
|
|
query=$(echo "db/$1?folder=$(expr "${path%%/*}" \& "$path" \| data)
|
|
|
|
$(expr levels \& "$1" = "browse" \| page)=${depth:-1}
|
|
|
|
$(case "$path" in (*/*) echo "$(expr "prefix" \& "$1" = "browse" \| "$1")=${path#*/}";; esac)" |
|
|
|
|
tr -d ' ' | paste -s -d'&');;
|
2021-07-04 17:42:20 +00:00
|
|
|
(*) query="$1";;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
curl --silent -H 'Content-Type: application/json' -H "X-API-Key: $apikey" "http://localhost:8384/rest/$query" "$@" | bat --style=numbers -l json
|
|
|
|
fi
|