diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-06-27 11:52:24 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-06-27 12:02:28 -0400 |
commit | d9bcbaf71b0173fe44d7e07c05d110c49c07b6f2 (patch) | |
tree | 8e2941b2ccddc656d6d60cb90e62fe0ec4292743 | |
parent | 1313875b02c690ca5a40e585d24fdec240bb419d (diff) | |
download | bfs-d9bcbaf71b0173fe44d7e07c05d110c49c07b6f2.tar.xz |
tests: Get more tests passing with --bfs=tests/find-color.sh
-rwxr-xr-x | tests/ls-color.sh | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/tests/ls-color.sh b/tests/ls-color.sh index 6d33f53..9fdd59c 100755 --- a/tests/ls-color.sh +++ b/tests/ls-color.sh @@ -7,17 +7,44 @@ set -e +function parse_ls_colors() { + for key; do + local -n var="$key" + if [[ "$LS_COLORS" =~ (^|:)$key=(([^:]|\\:)*) ]]; then + var="${BASH_REMATCH[2]}" + # Interpret escapes + var=$(printf "$var" | sed $'s/\^\[/\033/g; s/\\\\:/:/g') + fi + done +} + +function re_escape() { + # https://stackoverflow.com/a/29613573/502399 + sed 's/[^^]/[&]/g; s/\^/\\^/g' <<<"$1" +} + +rs=0 +lc=$'\033[' +rc=m +ec= +no= + +parse_ls_colors rs lc rc ec no +: "${ec:=$lc$rs$rc}" + +strip="(($(re_escape "$lc$no$rc"))?($(re_escape "$ec")|$(re_escape "$lc$rc")))+" + +function ls_color() { + # Strip the leading reset sequence from the ls output + ls -1d --color "$@" | sed -E "s/^$strip([a-z].*)$strip/\4/; s/^$strip//" +} + L= if [ "$1" = "-L" ]; then L="$1" shift fi -function ls_color() { - # Strip the leading reset sequence from the ls output - ls -1d --color "$@" | sed $'s/^\033\\[0m//' -} - DIR="${1%/*}" if [ "$DIR" = "$1" ]; then ls_color "$1" |