Add Linux/Arch support to glm-quota
Use secret-tool on Linux and fix date command compatibility. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -6,12 +6,23 @@
|
||||
# glm-quota # show quota
|
||||
# glm-quota -v # show raw JSON response
|
||||
#
|
||||
# Setup API key (Keychain):
|
||||
# Setup API key (macOS Keychain):
|
||||
# security add-generic-password -a "$USER" -s GLM_API_KEY -w "YOUR_API_KEY"
|
||||
# Setup API key (Arch/Linux — libsecret):
|
||||
# echo "YOUR_API_KEY" | secret-tool store --label "GLM API Key" service GLM_API_KEY
|
||||
|
||||
KEY_NAME="GLM_API_KEY"
|
||||
URL="https://open.bigmodel.cn/api/monitor/usage/quota/limit"
|
||||
|
||||
# ===== OS DETECTION =====
|
||||
if [ -f /etc/arch-release ]; then
|
||||
OS="arch"
|
||||
elif [ "$(uname -s)" = "Darwin" ]; then
|
||||
OS="macos"
|
||||
else
|
||||
OS="linux"
|
||||
fi
|
||||
|
||||
# ===== COLORS =====
|
||||
GREEN="\033[1;32m"
|
||||
CYAN="\033[1;36m"
|
||||
@@ -25,9 +36,19 @@ VERBOSE=0
|
||||
[[ "$1" == "-v" ]] && VERBOSE=1
|
||||
|
||||
# ===== LOAD TOKEN =====
|
||||
case "$OS" in
|
||||
macos)
|
||||
API_TOKEN=$(security find-generic-password -a "$USER" -s "$KEY_NAME" -w 2>/dev/null | tr -d '\n')
|
||||
;;
|
||||
arch)
|
||||
API_TOKEN=$(secret-tool lookup service "$KEY_NAME" 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 -e "${RED}❌ API token not found in Keychain ($KEY_NAME)${RESET}"
|
||||
echo -e "${RED}❌ API token not found ($KEY_NAME)${RESET}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -66,7 +87,11 @@ read -r R_USAGE R_CURRENT R_REMAINING R_PERCENT R_RESET < <(echo "$RESPONSE" | j
|
||||
format_ms() {
|
||||
local ms="$1"
|
||||
if [ -n "$ms" ] && [ "$ms" -gt 0 ] 2>/dev/null; then
|
||||
date -r $((ms / 1000)) "+%Y-%m-%d %H:%M:%S" 2>/dev/null || echo "$ms"
|
||||
local sec=$((ms / 1000))
|
||||
case "$OS" in
|
||||
macos) date -r "$sec" "+%Y-%m-%d %H:%M:%S" 2>/dev/null || echo "$ms" ;;
|
||||
*) date -d "@$sec" "+%Y-%m-%d %H:%M:%S" 2>/dev/null || echo "$ms" ;;
|
||||
esac
|
||||
else
|
||||
echo "N/A"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user