Skip to content

fix(docs): use ANSI-C quoting for bash statusline badge example#57

Merged
JuliusBrussee merged 1 commit intoJuliusBrussee:mainfrom
jccidc:fix/bash-statusline-escape
Apr 11, 2026
Merged

fix(docs): use ANSI-C quoting for bash statusline badge example#57
JuliusBrussee merged 1 commit intoJuliusBrussee:mainfrom
jccidc:fix/bash-statusline-escape

Conversation

@jccidc
Copy link
Copy Markdown
Contributor

@jccidc jccidc commented Apr 9, 2026

Small docs fix — the bash statusline snippet in `hooks/README.md` has a real bug.

Problem

The current snippet uses double-quoted escape sequences:

```bash
caveman_text="\033[38;5;172m[CAVEMAN]\033[0m"
```

Bash does not interpret backslash escapes inside double quotes. Users who copy-paste this get the literal 19-character string `\033[38;5;172m[CAVEMAN]\033[0m` in their statusline instead of a colored badge.

You can verify with `printf`:

```bash
$ caveman_text="\033[38;5;172m[CAVEMAN]\033[0m"
$ printf '%s\n' "$caveman_text" | cat -v
\033[38;5;172m[CAVEMAN]\033[0m
```

No ESC character — just literal text.

Fix

Switch to ANSI-C quoted strings (`$'...'`), which bash does interpret:

```bash
caveman_text=$'\033[38;5;172m[CAVEMAN]\033[0m'
```

For the mode-variant line that needs to interpolate `${caveman_suffix}`, adjacent string concatenation preserves both the ANSI-C literal portions and the double-quoted expansion:

```bash
caveman_text=$'\033[38;5;172m[CAVEMAN:'"${caveman_suffix}"$']\033[0m'
```

Verified with `bash -c ... | cat -v`:

```
^[[38;5;172m[CAVEMAN]^[[0m
^[[38;5;172m[CAVEMAN:ULTRA]^[[0m
```

`^[` is the visible representation of ESC (0x1B). Both variants now produce real escape sequences, and the badge renders with color in a terminal.

Scope

  • 2 lines changed in `hooks/README.md`
  • No other files touched
  • No behavior change — purely a docs fix so copy-paste works

This is one of a small batch of docs and install.sh quality-of-life PRs I'm sending today. Each one is independent and can be merged in any order. Close any that don't fit your vision — no pressure. 🪨

The bash snippet in hooks/README.md uses double-quoted escape
sequences like '\033[38;5;172m[CAVEMAN]\033[0m', but bash does
not interpret backslash escapes inside double quotes. Users who
copy-paste the example get the literal 19-character string
'\033[38;5;172m[CAVEMAN]\033[0m' in their statusline instead of
a colored badge.

Fix by switching to ANSI-C quoted strings ($'...'), where bash
does interpret \033 as the ESC character. For the mode-variant
line that needs to interpolate the uppercase suffix, adjacent
string concatenation preserves both the ANSI-C literal portions
and the double-quoted variable expansion.

Verified via 'bash -c ... | cat -v' that both variants now render
the actual ESC character (0x1B, shown as ^[ by cat -v).

Before: "\033[38;5;172m[CAVEMAN]\033[0m"           (literal string)
After:  $'\033[38;5;172m[CAVEMAN]\033[0m'            (interpreted escape)
jccidc added a commit to jccidc/caveman-harness that referenced this pull request Apr 9, 2026
@JuliusBrussee JuliusBrussee requested a review from Copilot April 9, 2026 20:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a copy-paste bug in the hooks/README.md statusline badge example by switching from double-quoted strings (which keep \033 literal in bash) to ANSI-C quoting so the snippet produces real terminal escape sequences.

Changes:

  • Replace "\033..." with $'\033...' for the non-suffixed badge example.
  • Use bash adjacent-string concatenation to keep ANSI escapes literal while still expanding ${caveman_suffix}.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JuliusBrussee JuliusBrussee merged commit 8be1bdd into JuliusBrussee:main Apr 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants