1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#!/usr/bin/env bash
# scripts/add-item.sh — quick add via Gum.
# Requires: gum, jq, curl. Token at ~/.${APP_SLUG}rc.json.
set -euo pipefail
: "${APP_BASE:=http://localhost:3000}"
: "${APP_SLUG:=app}"
CONFIG="$HOME/.${APP_SLUG}rc.json"
if [ ! -f "$CONFIG" ]; then
gum style --foreground 196 "No token. Get one at $APP_BASE/settings/tokens and save to $CONFIG"
exit 1
fi
TOKEN=$(jq -r .token "$CONFIG")
TITLE=$(gum input --placeholder "Title")
[ -z "$TITLE" ] && exit 0
gum spin --spinner dot --title "Saving…" -- \
curl -sf -X POST "$APP_BASE/api/items" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg t "$TITLE" '{title:$t}')"
gum style --foreground 212 "Added: $TITLE"
|