From a15563e145788f5200946acd23e18e2cd4a93171 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Wed, 10 Jun 2020 03:13:48 +0000 Subject: [PATCH] =?UTF-8?q?chmod/=20output=20colorization=20(by=20iiv?= =?UTF-8?q?=C3=A5n)=20(#197)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/frontend/ansi.py | 2 ++ share/adapters/chmod.grc | 40 ++++++++++++++++++++++++++++++++++++++++ share/adapters/chmod.sh | 4 +++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 share/adapters/chmod.grc diff --git a/lib/frontend/ansi.py b/lib/frontend/ansi.py index 643612b..dd15ec0 100644 --- a/lib/frontend/ansi.py +++ b/lib/frontend/ansi.py @@ -129,6 +129,8 @@ def _visualize(answers, request_options, search_mode=False): and not request_options.get('add_comments') and not request_options.get('remove_text'))) + if request_options.get('no-terminal'): + result = remove_ansi(result) result = result.strip('\n') + "\n" return result, found diff --git a/share/adapters/chmod.grc b/share/adapters/chmod.grc new file mode 100644 index 0000000..7f643a6 --- /dev/null +++ b/share/adapters/chmod.grc @@ -0,0 +1,40 @@ +# with option -sI +# e.g. grc curl -sI mysite.com +# http +regexp=^(HTTP).* +colours=yellow +====== +# server +regexp=^(Server).* +colours=cyan +====== +# site +regexp=^(Link).* +colours=magenta +====== +# colouring the output of script 'cheat chmod' +# e.g. grc curl -s cheat.sh/chmod/755 +# linux string +regexp=^(Linux.*Permissions).*(String:)\s+(.*)$ +colours=yellow,green,red +====== +# linux number +regexp=^(Linux.*Permissions).*(Number:)\s+(.*)$ +colours=yellow,green,red +====== +# header +regexp=^(Special)\s+(Owner)\s+(Group)\s+(Public)$ +colours=white +====== +# setuid +regexp=^(Setuid)\s+\[.*\].*(Read).* +colours=green,bold cyan +====== +# setgid +regexp=^(Setgid)\s+\[.*\].*(Write).* +colours=green,bold yellow +====== +# sticky bit +regexp=^(Sticky bit)\s+\[.*\].*(Execute).* +colours=green,bold magenta +====== diff --git a/share/adapters/chmod.sh b/share/adapters/chmod.sh index 62bdec5..233cb4c 100755 --- a/share/adapters/chmod.sh +++ b/share/adapters/chmod.sh @@ -2,6 +2,8 @@ # Contributed by Erez Binyamin (github.com/ErezBinyamin) +GRC_STYLESHEET="${BASH_SOURCE[0]}"; GRC_STYLESHEET=${GRC_STYLESHEET%.sh}.grc + # Translate between chmod string and number # Inspired by http://permissions-calculator.org/ # Contrib to chubin - cheat.sh @@ -89,7 +91,7 @@ Setuid [$setuid]\tRead [${R[0]}]\tRead [${R[1]}]\tRead [${R[2]}] Setgid [$setgid]\tWrite [${W[0]}]\tWrite [${W[1]}]\tWrite [${W[2]}] Sticky bit [$sticky]\tExecute [${X[0]}]\tExecute [${X[1]}]\tExecute [${X[2]}] -" +" | grcat "$GRC_STYLESHEET" } chmod_calc $@