mirror of
https://github.com/theniceboy/.config.git
synced 2025-12-26 22:54:59 +08:00
hide items in tmux statusline width for thinner viewport
This commit is contained in:
parent
61ace2ef02
commit
9b9ed00ee2
2 changed files with 57 additions and 1 deletions
|
|
@ -28,6 +28,23 @@ separator=""
|
|||
left_cap="█"
|
||||
max_width=18
|
||||
|
||||
# width-based label policy: when narrow (<80 cols by default),
|
||||
# show title for active session and only the numeric index for inactive ones.
|
||||
left_narrow_width=${TMUX_LEFT_NARROW_WIDTH:-80}
|
||||
term_width=$(tmux display-message -p '#{client_width}' 2>/dev/null || true)
|
||||
if [[ -z "${term_width:-}" || "$term_width" == "0" ]]; then
|
||||
term_width=$(tmux display-message -p '#{window_width}' 2>/dev/null || true)
|
||||
fi
|
||||
if [[ -z "${term_width:-}" || "$term_width" == "0" ]]; then
|
||||
term_width=${COLUMNS:-}
|
||||
fi
|
||||
is_narrow=0
|
||||
if [[ -n "${term_width:-}" && "$term_width" =~ ^[0-9]+$ ]]; then
|
||||
if (( term_width < left_narrow_width )); then
|
||||
is_narrow=1
|
||||
fi
|
||||
fi
|
||||
|
||||
normalize_session_id() {
|
||||
local value="$1"
|
||||
value="${value#\$}"
|
||||
|
|
@ -43,6 +60,15 @@ trim_label() {
|
|||
fi
|
||||
}
|
||||
|
||||
extract_index() {
|
||||
local value="$1"
|
||||
if [[ "$value" =~ ^([0-9]+)-.*$ ]]; then
|
||||
printf '%s' "${BASH_REMATCH[1]}"
|
||||
else
|
||||
printf ''
|
||||
fi
|
||||
}
|
||||
|
||||
tracker_pending_sessions=""
|
||||
tracker_running_sessions=""
|
||||
TRACKER_CACHE_DIR="$HOME/.config/tmux/cache"
|
||||
|
|
@ -176,12 +202,27 @@ while IFS= read -r entry; do
|
|||
segment_bg="$inactive_bg"
|
||||
segment_fg="$inactive_fg"
|
||||
trimmed_name=$(trim_label "$name")
|
||||
is_current=0
|
||||
if [[ "$session_id" == "$current_session_id" || "$session_id_norm" == "$current_session_id_norm" || "$trimmed_name" == "$current_session_trimmed" ]]; then
|
||||
is_current=1
|
||||
segment_bg="$active_bg"
|
||||
segment_fg="$active_fg"
|
||||
fi
|
||||
|
||||
label="$trimmed_name"
|
||||
if (( is_narrow == 1 )); then
|
||||
if (( is_current == 1 )); then
|
||||
label="$trimmed_name" # active: show TITLE (trim N-)
|
||||
else
|
||||
idx=$(extract_index "$name")
|
||||
if [[ -n "$idx" ]]; then
|
||||
label="$idx"
|
||||
else
|
||||
label="$trimmed_name"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
label="$trimmed_name" # wide: current behavior (TITLE everywhere)
|
||||
fi
|
||||
if (( ${#label} > max_width )); then
|
||||
label="${label:0:max_width-1}…"
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -1,6 +1,21 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# hide entire right status if terminal width is below threshold
|
||||
min_width=${TMUX_RIGHT_MIN_WIDTH:-90}
|
||||
width=$(tmux display-message -p '#{client_width}' 2>/dev/null || true)
|
||||
if [[ -z "${width:-}" || "$width" == "0" ]]; then
|
||||
width=$(tmux display-message -p '#{window_width}' 2>/dev/null || true)
|
||||
fi
|
||||
if [[ -z "${width:-}" || "$width" == "0" ]]; then
|
||||
width=${COLUMNS:-}
|
||||
fi
|
||||
if [[ -n "${width:-}" && "$width" =~ ^[0-9]+$ ]]; then
|
||||
if (( width < min_width )); then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
status_bg=$(tmux show -gqv status-bg)
|
||||
if [[ -z "$status_bg" || "$status_bg" == "default" ]]; then
|
||||
status_bg=black
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue