support arch

This commit is contained in:
2026-04-20 14:53:03 +07:00
parent 0d8793426f
commit 09aaab2e42
2 changed files with 35 additions and 5 deletions
+22 -4
View File
@@ -1,10 +1,12 @@
#!/usr/bin/env bash
: <<'DOC'
ask — AI terminal assistant (macOS)
ask — AI terminal assistant (macOS/Linux)
Setup API key (Keychain):
Setup API key (macOS Keychain):
security add-generic-password -a "$USER" -s TK_AI_API_TOKEN -w "YOUR_API_KEY"
Setup API key (Arch/Linux — libsecret):
echo "YOUR_API_KEY" | secret-tool store --label "AI API Token" service TK_AI_API_TOKEN
Usage:
ask "question"
@@ -17,6 +19,15 @@ SERVER="https://ai.acbpro.com/v1/chat/completions"
MODEL="gpt-5.3-codex"
KEY_NAME="TK_AI_API_TOKEN"
# ===== OS DETECTION =====
if [ -f /etc/arch-release ]; then
OS="arch"
elif [ "$(uname -s)" = "Darwin" ]; then
OS="macos"
else
OS="linux"
fi
VERBOSE=0
INTERACTIVE=0
@@ -37,10 +48,17 @@ while [[ "$1" == -* ]]; do
done
# ===== LOAD TOKEN =====
API_TOKEN=$(security find-generic-password -a "$USER" -s "$KEY_NAME" -w 2>/dev/null | tr -d '\n')
case "$OS" in
macos)
API_TOKEN=$(security find-generic-password -a "$USER" -s "$KEY_NAME" -w 2>/dev/null | tr -d '\n')
;;
*)
API_TOKEN=$(secret-tool lookup service "$KEY_NAME" 2>/dev/null | tr -d '\n')
;;
esac
if [ -z "$API_TOKEN" ]; then
echo "❌ API token not found in Keychain ($KEY_NAME)"
echo "❌ API token not found ($KEY_NAME)" >&2
exit 1
fi
+13 -1
View File
@@ -33,7 +33,14 @@ RESET="\033[0m"
# ===== ARGS =====
VERBOSE=0
[[ "$1" == "-v" ]] && VERBOSE=1
ONELINE=0
while [[ $# -gt 0 ]]; do
case "$1" in
-v) VERBOSE=1 ;;
-1) ONELINE=1 ;;
esac
shift
done
# ===== LOAD TOKEN =====
case "$OS" in
@@ -118,6 +125,11 @@ fi
ICON=$(awk -v p="$T_PERCENT" 'BEGIN { if (p < 50) print "🟢"; else if (p > 80) print "🔴"; else print "🟡" }')
if [ "$ONELINE" -eq 1 ]; then
echo "GLM: ${T_PERCENT}%${REMAIN}${ICON}"
exit 0
fi
echo "GLM: ${T_PERCENT}%${REMAIN}${ICON}"
echo "---"
echo "✅ Account: ${LEVEL}"