From 5cf8feee5342244aacad5471bbc5a696ec158c2e Mon Sep 17 00:00:00 2001 From: Andrej Date: Fri, 25 Oct 2019 10:41:05 +0200 Subject: [PATCH 1/2] refactor checkUtils: remove repeating commands putting checked utils into array and running through the array in for loop cleans the code --- git-quick-stats | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/git-quick-stats b/git-quick-stats index 1129cdb..51a7ccf 100755 --- a/git-quick-stats +++ b/git-quick-stats @@ -35,21 +35,13 @@ _theme="${_MENU_THEME:=default}" ################################################################################ function checkUtils() { local -r msg="not found. Please make sure this is installed and in PATH." - - command -v awk >/dev/null 2>&1 || { echo >&2 "awk ${msg}"; exit 1; } - command -v basename >/dev/null 2>&1 || { echo >&2 "basename ${msg}"; exit 1; } - command -v cat >/dev/null 2>&1 || { echo >&2 "cat ${msg}"; exit 1; } - command -v column >/dev/null 2>&1 || { echo >&2 "column ${msg}"; exit 1; } - command -v echo >/dev/null 2>&1 || { echo >&2 "echo ${msg}"; exit 1; } - command -v git >/dev/null 2>&1 || { echo >&2 "git ${msg}"; exit 1; } - command -v grep >/dev/null 2>&1 || { echo >&2 "grep ${msg}"; exit 1; } - command -v head >/dev/null 2>&1 || { echo >&2 "head ${msg}"; exit 1; } - command -v seq >/dev/null 2>&1 || { echo >&2 "seq ${msg}"; exit 1; } - command -v sort >/dev/null 2>&1 || { echo >&2 "sort ${msg}"; exit 1; } - command -v tput >/dev/null 2>&1 || { echo >&2 "tput ${msg}"; exit 1; } - command -v tr >/dev/null 2>&1 || { echo >&2 "tr ${msg}"; exit 1; } - command -v uniq >/dev/null 2>&1 || { echo >&2 "uniq ${msg}"; exit 1; } - command -v wc >/dev/null 2>&1 || { echo >&2 "wc ${msg}"; exit 1; } + declare -a utils=("awk" "basename" "cat" "column" "echo" "git" "grep" "head" + "seq" "sort" "tput" "tr" "uniq" "wc") + + for u in "${utils[@]}" + do + command -v "$u" >/dev/null 2>&1 || { echo >&2 "$u ${msg}"; exit 1; } + done } ################################################################################ From c8ad2fba842ddf7452cc250eff5fda7cafaebc41 Mon Sep 17 00:00:00 2001 From: Andrej Date: Fri, 25 Oct 2019 14:23:15 +0200 Subject: [PATCH 2/2] array of util names are read only now --- git-quick-stats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-quick-stats b/git-quick-stats index 51a7ccf..3d2180a 100755 --- a/git-quick-stats +++ b/git-quick-stats @@ -35,7 +35,7 @@ _theme="${_MENU_THEME:=default}" ################################################################################ function checkUtils() { local -r msg="not found. Please make sure this is installed and in PATH." - declare -a utils=("awk" "basename" "cat" "column" "echo" "git" "grep" "head" + declare -ar utils=("awk" "basename" "cat" "column" "echo" "git" "grep" "head" "seq" "sort" "tput" "tr" "uniq" "wc") for u in "${utils[@]}"