From 05aa4ba092091e84dd690fc3db50e586825639b1 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Tue, 19 Sep 2023 02:23:03 +0300 Subject: [PATCH] feat(scripts): use bkt for command caching --- scripts/shared.sh | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/scripts/shared.sh b/scripts/shared.sh index df5d44c..a12239a 100755 --- a/scripts/shared.sh +++ b/scripts/shared.sh @@ -197,11 +197,32 @@ function menu_usage() done } +# Cache commands using bkt if installed +if command -v bkt >&/dev/null; then + bkt() + { + command bkt "$@" + } +else + # If bkt isn't installed skip its arguments and just execute directly. + # Optionally write a msg to stderr suggesting users install bkt. + bkt() + { + while [[ "$1" == --* ]]; do shift; done + "$@" + } +fi + # shorthand for checking if the system has the bin in path. # usage: have php && php -v function have { - command -v "$1" >&/dev/null + bkt -- command -v "$1" >&/dev/null +} + +function brew_installed +{ + bkt -- brew list } # shorthand for checking if brew package is installed @@ -210,7 +231,7 @@ function have_brew { ! have brew && return 125 - if brew list "$1" &> /dev/null; then + if bkt -- brew list "$1" &> /dev/null; then return 0 else return 1