git:last-changed: Support ANSI escape sequences

When passing --color to `ls` and the entry were colored, git would not
return a commit due to the escape sequences.
This commit is contained in:
2023-01-17 01:39:43 +01:00
parent f317ed81c2
commit 9f0ffcb6ca

View File

@@ -7,7 +7,8 @@
ls -1 "$@" \
| while read -r line; do
git_info="$(git log -1 --format=$'%ci\t%s' "$line")"
sanitized_line="$(sed 's/\x1b[^m]*m//g' <<<"$line")"
git_info="$(git log -1 --format=$'%ci\t%s' "$sanitized_line")"
printf "%s\t%s\n" "$line" "$git_info"
done \
| sort -r -t$'\t' -k2,2 \