Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions home/dot_claude/statusline-command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#
# Line 1 (status): model | effort | context bar | cost | 5h rate limit
# Line 2 (location): dir | worktree | branch | agent
#
# shellcheck disable=SC2154 # most vars are assigned via the jq | eval block below

input=$(cat)

Expand Down Expand Up @@ -43,13 +41,19 @@ make_bar() {
pct=${1%.*}
[ -z "$pct" ] && pct=0
width=10
filled=$(( pct * width / 100 ))
filled=$((pct * width / 100))
[ "$filled" -gt "$width" ] && filled=$width
[ "$filled" -lt 0 ] && filled=0
i=0
bar=""
while [ "$i" -lt "$filled" ]; do bar="${bar}█"; i=$(( i + 1 )); done
while [ "$i" -lt "$width" ]; do bar="${bar}░"; i=$(( i + 1 )); done
while [ "$i" -lt "$filled" ]; do
bar="${bar}█"
i=$((i + 1))
done
while [ "$i" -lt "$width" ]; do
bar="${bar}░"
i=$((i + 1))
done
printf '%s' "$bar"
}

Expand All @@ -59,9 +63,12 @@ make_bar() {
threshold_color() {
pct=${1%.*}
[ -z "$pct" ] && pct=0
if [ "$pct" -ge 90 ]; then printf '%s' "$RED"
elif [ "$pct" -ge 70 ]; then printf '%s' "$YELLOW"
else printf '%s' "$GREEN"
if [ "$pct" -ge 90 ]; then
printf '%s' "$RED"
elif [ "$pct" -ge 70 ]; then
printf '%s' "$YELLOW"
else
printf '%s' "$GREEN"
fi
}

Expand All @@ -71,16 +78,18 @@ threshold_color() {
fmt_reset_time() {
ts="$1"
[ -z "$ts" ] && return
date -r "$ts" "+%-I:%M%p" 2>/dev/null \
|| date -d "@$ts" "+%-I:%M%p" 2>/dev/null
date -r "$ts" "+%-I:%M%p" 2>/dev/null ||
date -d "@$ts" "+%-I:%M%p" 2>/dev/null
}

# @description Format one rate-limit block.
# @arg $1 string Usage percentage.
# @arg $2 string Reset Unix timestamp.
# @arg $3 string Label (e.g., "5h", "7d").
format_rate_limit() {
pct="$1"; reset_ts="$2"; label="$3"
pct="$1"
reset_ts="$2"
label="$3"
[ -z "$pct" ] && return
pct_int=${pct%.*}
color=$(threshold_color "$pct_int")
Expand All @@ -99,8 +108,12 @@ format_rate_limit() {
# @arg $2 string Segment to append.
sep=" ${DIM}|${RST} "
add_segment() {
base="$1"; seg="$2"
[ -z "$seg" ] && { printf '%s' "$base"; return; }
base="$1"
seg="$2"
[ -z "$seg" ] && {
printf '%s' "$base"
return
}
if [ -z "$base" ]; then
printf '%s' "$seg"
else
Expand All @@ -112,11 +125,12 @@ add_segment() {
line1=""

# Model
# shellcheck disable=SC2154 # assigned by the jq | eval block above

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep SC2154 suppressed for all eval-assigned fields

Because the CI lint job runs mise lint, this narrowed disable leaves the other variables populated only through eval "$(jq ...)" (effort, used, remaining, total_cost, current_dir, worktree, agent_name) uncovered; ShellCheck's SC2154 documentation explicitly says it does not infer dynamic assignments such as eval var=value. With home/dot_claude now in shell_roots, lint will still fail on those references rather than bringing this script into the lint surface.

Useful? React with 👍 / 👎.

line1=$(add_segment "$line1" "🤖 $model")

# Effort (💪 emoji, suppressed when missing or "default")
[ -n "$effort" ] && [ "$effort" != "default" ] \
&& line1=$(add_segment "$line1" "💪 $effort")
[ -n "$effort" ] && [ "$effort" != "default" ] &&
line1=$(add_segment "$line1" "💪 $effort")

# Context window — show used%, color-coded by threshold (no bar; the number is the signal)
if [ -n "$used" ]; then
Expand All @@ -125,7 +139,7 @@ if [ -n "$used" ]; then
line1=$(add_segment "$line1" "🧠 ${color}${used_int}%${RST}")
elif [ -n "$remaining" ]; then
rem_int=${remaining%.*}
used_int=$(( 100 - rem_int ))
used_int=$((100 - rem_int))
color=$(threshold_color "$used_int")
line1=$(add_segment "$line1" "🧠 ${color}${used_int}%${RST}")
fi
Expand All @@ -137,6 +151,7 @@ if [ -n "$total_cost" ]; then
fi

# 5-hour rate limit
# shellcheck disable=SC2154 # assigned by the jq | eval block above
rl_5h=$(format_rate_limit "$rl_5h_pct" "$rl_5h_reset" "5h")
[ -n "$rl_5h" ] && line1=$(add_segment "$line1" "⏱️ $rl_5h")

Expand All @@ -161,7 +176,7 @@ fi
if [ -n "$current_dir" ]; then
git_str=$(
cd "$current_dir" 2>/dev/null || exit 0
git rev-parse --git-dir > /dev/null 2>&1 || exit 0
git rev-parse --git-dir >/dev/null 2>&1 || exit 0
b=$(git branch --show-current 2>/dev/null)
[ -z "$b" ] && b=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
s=$(git diff --cached --numstat 2>/dev/null | wc -l | tr -d ' ')
Expand Down
18 changes: 16 additions & 2 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ set -euo pipefail

shell_roots=()
has_shell_roots=0
for root in scripts home/dot_config/zsh home/.chezmoitemplates .github/actions; do
for root in scripts home/dot_config/zsh home/.chezmoitemplates home/dot_claude .github/actions; do
if [[ -d "${root}" ]]; then
shell_roots+=("${root}")
has_shell_roots=1
Expand Down Expand Up @@ -63,7 +63,7 @@ mise exec -- prettier --check .

shell_roots=()
has_shell_roots=0
for root in scripts home/dot_config/zsh home/.chezmoitemplates .github/actions; do
for root in scripts home/dot_config/zsh home/.chezmoitemplates home/dot_claude .github/actions; do
if [[ -d "${root}" ]]; then
shell_roots+=("${root}")
has_shell_roots=1
Expand All @@ -82,6 +82,20 @@ if ((has_shell_roots)); then
fi
fi

# bats files use a test DSL that shfmt would reflow, so lint them with shellcheck only.
# Severity stays at warning because bats idioms (literal-string assertions, per-test
# subshells) trip info-level checks that are not real bugs.
if [[ -d tests ]]; then
bats_targets=()
while IFS= read -r bats_target; do
bats_targets+=("${bats_target}")
done < <(find tests -type f -name '*.bats')

if [[ -n "${bats_targets[*]:-}" ]]; then
mise exec -- shellcheck --shell=bash --severity=warning "${bats_targets[@]}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stop parsing Bats tests as plain Bash

Existing tests use native Bats @test blocks, and Bats documents that this syntax is not Bash-compliant while ShellCheck's --shell option overrides shebang/extension detection. Forcing --shell=bash here makes mise lint parse every .bats file as plain Bash (the same issue is also reinforced by the repo .shellcheckrc), so the new test lint pass fails before it can report useful diagnostics.

Useful? React with 👍 / 👎.

fi
fi

mise exec -- taplo fmt --check
'''

Expand Down
1 change: 0 additions & 1 deletion tests/unit/vscode-settings.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ load '../test_helpers/load.bash'
SOURCE_DIR="$DOTFILES_ROOT/home"
SETTINGS_TEMPLATE="$DOTFILES_ROOT/home/Library/Application Support/Code/User/settings.json"
PERSONAL_DATA='{"chezmoi":{"os":"darwin"},"personal":true,"work":false}'
WORK_DATA='{"chezmoi":{"os":"darwin"},"personal":false,"work":true}'

render_settings() {
local data="$1"
Expand Down
Loading