/statusline generates command with non-zero exit code and printf bug
Description
The /statusline slash command generates an inline shell command for settings.json that has two bugs:
1. Non-zero exit code
The generated command ends with:
[ "$style" != "default" ] && printf " \033[90m[$style]\033[0m"
When $style is "default" (the common case), the [ test returns exit code 1. Per the docs, "scripts that exit with non-zero codes or produce no output cause the status line to go blank." This means the statusline silently doesn't display for most users.
Fix: Append ; true or || true to ensure the command always exits 0.
2. printf format string injection
The generated command embeds variables directly in printf format strings:
printf "\033[33m $branch$status \033[0m"
ctx=$(printf " \033[36m ${remaining}%% \033[0m")
printf "\033[31m $user\033[0m ... ${ctx} ..."
The ctx variable ends up containing a literal % (from the %% in the inner printf). When ${ctx} is expanded in the outer printf format string, that % is interpreted as a format specifier, producing:
bash: line 0: printf: `%': invalid format character
Fix: Use %s placeholders with variables as separate arguments:
printf "\033[33m %s%s \033[0m" "$branch" "$status"
Steps to reproduce
- Run
/statuslinewith any description (e.g., "show model, git branch, context, time") - Observe the statusline doesn't appear
- Test the generated command manually — it exits with code 1 and prints a printf error
Expected behavior
The generated command should exit 0 and use safe printf format strings.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗