mirror of
https://github.com/theniceboy/.config.git
synced 2026-05-11 09:28:11 +08:00
agent tracker update
This commit is contained in:
parent
5064629d61
commit
0bfcb8d7c3
31 changed files with 1741 additions and 3320 deletions
|
|
@ -1,11 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Args: <pane_pid> <pane_width> <pane_path> <pane_cmd>
|
||||
# Args: <pane_pid> <pane_id> <pane_tty> <pane_title> <pane_width> <pane_path> <pane_cmd>
|
||||
pid="${1:-}"
|
||||
width="${2:-80}"
|
||||
pane_path="${3:-$PWD}"
|
||||
pane_cmd="${4:-}"
|
||||
pane_id="${2:-}"
|
||||
pane_tty="${3:-}"
|
||||
pane_title="${4:-}"
|
||||
width="${5:-80}"
|
||||
pane_path="${6:-$PWD}"
|
||||
pane_cmd="${7:-}"
|
||||
ps_line=""
|
||||
|
||||
# Best-effort: inherit venv/conda from the pane's process env
|
||||
if [[ -n "$pid" ]]; then
|
||||
|
|
@ -26,10 +30,58 @@ strip_wrappers() {
|
|||
}
|
||||
|
||||
run_starship() {
|
||||
local cfg
|
||||
local prompt_width cfg
|
||||
prompt_width="${1:-$width}"
|
||||
cfg="${STARSHIP_TMUX_CONFIG:-$HOME/.config/starship-tmux.toml}"
|
||||
STARSHIP_LOG=error STARSHIP_CONFIG="$cfg" \
|
||||
starship prompt --terminal-width "$width" | strip_wrappers | tr -d '\n'
|
||||
starship prompt --terminal-width "$prompt_width" | strip_wrappers | tr -d '\n'
|
||||
}
|
||||
|
||||
trim_to_width() {
|
||||
local text max
|
||||
text="$1"
|
||||
max="$2"
|
||||
if (( ${#text} <= max )); then
|
||||
printf '%s' "$text"
|
||||
return
|
||||
fi
|
||||
if (( max <= 1 )); then
|
||||
printf ''
|
||||
return
|
||||
fi
|
||||
printf '%s…' "${text:0:$((max - 1))}"
|
||||
}
|
||||
|
||||
load_option() {
|
||||
local option value
|
||||
option="$1"
|
||||
[[ -n "$pane_id" ]] || return 0
|
||||
value=$(tmux display-message -p -t "$pane_id" "#{${option}}" 2>/dev/null | tr -d '\r\n' || true)
|
||||
value=$(printf '%s' "$value" | perl -0pe 's/\s+/ /g; s/^\s+|\s+$//g')
|
||||
printf '%s' "$value"
|
||||
}
|
||||
|
||||
clear_work_labels() {
|
||||
[[ -n "$pane_id" ]] || return 0
|
||||
tmux set-option -p -u -t "$pane_id" @op_work_theme 2>/dev/null || true
|
||||
tmux set-option -p -u -t "$pane_id" @op_work_now 2>/dev/null || true
|
||||
tmux set-option -p -u -t "$pane_id" @op_work_summary 2>/dev/null || true
|
||||
}
|
||||
|
||||
opencode_active() {
|
||||
local tty_name tty_ps
|
||||
[[ "$pane_title" == OC\ \|* ]] && return 0
|
||||
[[ "$pane_cmd" == "op" || "$pane_cmd" == "opencode" ]] && return 0
|
||||
tty_name="${pane_tty#/dev/}"
|
||||
tty_ps=""
|
||||
if [[ -n "$tty_name" ]]; then
|
||||
tty_ps=$(ps -t "$tty_name" -o command= 2>/dev/null || true)
|
||||
elif [[ -n "$ps_line" ]]; then
|
||||
tty_ps="$ps_line"
|
||||
fi
|
||||
[[ "$pane_cmd" == "node" && "$tty_ps" == *"/bin/opencode"* ]] && return 0
|
||||
[[ "$pane_cmd" == "node" && "$tty_ps" == *"opencode-ai/bin/.opencode"* ]] && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
fallback() {
|
||||
|
|
@ -40,8 +92,52 @@ fallback() {
|
|||
}
|
||||
|
||||
if command -v starship >/dev/null 2>&1; then
|
||||
(cd "$pane_path" && run_starship) || fallback
|
||||
title=$(cd "$pane_path" && run_starship) || title=$(fallback)
|
||||
else
|
||||
fallback
|
||||
title=$(fallback)
|
||||
fi
|
||||
|
||||
theme=$(load_option "@op_work_theme")
|
||||
if [[ -z "$theme" ]]; then
|
||||
theme=$(load_option "@op_work_summary")
|
||||
fi
|
||||
now=$(load_option "@op_work_now")
|
||||
|
||||
if ! opencode_active; then
|
||||
if [[ -n "$theme" || -n "$now" ]]; then
|
||||
clear_work_labels
|
||||
fi
|
||||
printf '%s' "$title"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
summary_display=""
|
||||
if [[ -n "$theme" ]]; then
|
||||
summary_display="[$theme]"
|
||||
fi
|
||||
if [[ -n "$now" ]]; then
|
||||
if [[ -n "$summary_display" ]]; then
|
||||
summary_display="$summary_display ↳ $now"
|
||||
else
|
||||
summary_display="↳ $now"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$summary_display" ]]; then
|
||||
printf '%s' "$title"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
reserved_width=$((${#summary_display} + 3))
|
||||
prompt_width=$((width - reserved_width))
|
||||
if (( prompt_width < 16 )); then
|
||||
summary_display=$(trim_to_width "$summary_display" "$width")
|
||||
printf '%s' "$summary_display"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if command -v starship >/dev/null 2>&1; then
|
||||
title=$(cd "$pane_path" && run_starship "$prompt_width") || title=$(fallback)
|
||||
fi
|
||||
|
||||
printf '%s · %s' "$summary_display" "$title"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue