mirror of
https://github.com/theniceboy/.config.git
synced 2026-02-22 21:05:57 +08:00
agent tracker updates
This commit is contained in:
parent
689cc061cd
commit
bb2a53206b
13 changed files with 375 additions and 106 deletions
32
tmux/tmux-status/tracker_cache.sh
Executable file
32
tmux/tmux-status/tracker_cache.sh
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
CACHE_FILE="/tmp/tmux-tracker-cache.json"
|
||||
CACHE_MAX_AGE=1
|
||||
|
||||
tracker_client="$HOME/.config/agent-tracker/bin/tracker-client"
|
||||
|
||||
# Check if cache is fresh enough
|
||||
if [[ -f "$CACHE_FILE" ]]; then
|
||||
if [[ "$OSTYPE" == darwin* ]]; then
|
||||
file_age=$(( $(date +%s) - $(stat -f %m "$CACHE_FILE") ))
|
||||
else
|
||||
file_age=$(( $(date +%s) - $(stat -c %Y "$CACHE_FILE") ))
|
||||
fi
|
||||
if (( file_age < CACHE_MAX_AGE )); then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Simple lock using mkdir (atomic on all systems)
|
||||
LOCK_DIR="/tmp/tmux-tracker-cache.lock"
|
||||
if ! mkdir "$LOCK_DIR" 2>/dev/null; then
|
||||
exit 0
|
||||
fi
|
||||
trap 'rmdir "$LOCK_DIR" 2>/dev/null || true' EXIT
|
||||
|
||||
if [[ -x "$tracker_client" ]]; then
|
||||
"$tracker_client" state 2>/dev/null > "$CACHE_FILE.tmp" && mv "$CACHE_FILE.tmp" "$CACHE_FILE"
|
||||
else
|
||||
echo '{}' > "$CACHE_FILE"
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue