From 9152b5d4024fc3a22c78d2192723e23a4c3e18ff Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Tue, 19 Dec 2023 14:45:50 +0100 Subject: [PATCH] Add nocolor and noescape --- shell/colors | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shell/colors b/shell/colors index 844ce11..4e87793 100755 --- a/shell/colors +++ b/shell/colors @@ -16,4 +16,10 @@ alias grep=grep --color=auto [[ "$COLORTERM" == "gnome-terminal" ]] && export TERM=xterm-256color [[ "$COLORTERM" == "xfce4-terminal" ]] && export TERM=xterm-256color +function nocolor() { sed -e $'s/\x1b\[[0-9;]*m//g'; } + +function noescape() { perl -pe 's/\e\[[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e]//g;s/\e[PX^_].*?\e\\//g;s/\e\][^\a]*(?:\a|\e\\)//g;s/\e[\[\]A-Z\\^_@]//g;s/[\x00-\x1f\x7f-\x9f\xad]+//g;'; } + +function noescape() { sed -E $'s|\x1b\\[[0-\\?]*[ -/]*[@-~]||g;s|\x1b[PX^_][^\x1b]*\x1b\\\\||g;s:\x1b\\][^\x07]*(\x07|\x1b\\\\)::g;s|\x1b[@-_]||g'; } + # vim: ft=bash