From cffde0101e38095d3a3d8d7dacc1b23b8a1656f6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 7 Sep 2017 13:58:31 +0200 Subject: [PATCH] contrib/NM-log: improve script and make it sourceable - use "grep -a" so that grep doesn't refuse to work in binary input. - make the script source-able to only define the NM-colorize and NM-show-journal - In case the script is sourced, it also defines a NM-log function, which does the same as the script itself. - rename internal functions so that they have names starting with "NM" in case of sourcing. --- contrib/scripts/NM-log | 58 ++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/contrib/scripts/NM-log b/contrib/scripts/NM-log index 608fc386ab..7a35b17b10 100755 --- a/contrib/scripts/NM-log +++ b/contrib/scripts/NM-log @@ -13,7 +13,13 @@ # # You can pass multiple filenames. -show-journal() { +if [[ "$_" == "$0" ]]; then + NM_not_sourced=1 +else + unset NM_not_sourced +fi + +NM-show-journal() { local since="$(systemctl show NetworkManager | sed -n 's/^ExecMainStartTimestamp=\(.*\) [A-Z0-9]\+$/\1/p')" if [[ "$since" == "" ]]; then @@ -24,29 +30,37 @@ show-journal() { fi } -colorize() { +NM-colorize() { if [[ "$NM_LOG_NO_COLOR" == "" ]]; then - GREP_COLOR='01;33' grep --color=always '^\|^\(.* \)\?<\(warn>\|info> \|error>\) \(.*\.*$\)\?' | \ - GREP_COLOR='01;37' grep --color=always '^\|\\|info> \|error>\) \(.*\.*$\)\?' | \ + GREP_COLOR='01;37' grep -a --color=always '^\|\