From bbf9a1da58814b7d3a42e4c1969af52f5ff22e6b Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Wed, 30 Jul 2025 17:35:35 +0200 Subject: [PATCH] bin:no-ansi-sgr: Set LC_ALL=C for `[0-?]` range Setting LC_ALL=C makes it possible to use the range `[0-?]` instead of splitting it into `[0-9:-?]` as done previously. Without LC_ALL, sed complains with: sed: -e expression #1, char 21: Invalid range end The GNU manual explains this partially, although I still don't quite understand why this range specifically does not work in `en_US.utf8`. See: > Within a bracket expression, a *range expression* consists of two > characters separated by a hyphen. It matches any single character that > sorts between the two characters, inclusive. In the default C locale, > the sorting sequence is the native character order; for example, > `[a-d]` is equivalent to `[abcd]`. Link: https://www.gnu.org/software/sed/manual/sed.html#Character-Classes-and-Bracket-Expressions --- .local/bin/no-ansi-sgr | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.local/bin/no-ansi-sgr b/.local/bin/no-ansi-sgr index 3565750..fdf8892 100755 --- a/.local/bin/no-ansi-sgr +++ b/.local/bin/no-ansi-sgr @@ -1,9 +1,8 @@ -#!/bin/sed -f +#!/bin/sh # SPDX-License-Identifier: MIT # Copyright (c) 2025 Julian Prein # # Remove ANSI SGR (Select Graphic Rendition) escape sequences, e.g. setting # color or bold font. -# TODO: Why is the range `[0-?]` invalid? -s/\[[0-9:-?]*[ -/]*m//g +env LC_ALL=C sed 's/\[[0-?]*[ -/]*m//g'