From 8a36f21ca1f828b7a84d7a022993415ee870012d Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Wed, 21 Oct 2020 00:14:11 +0300 Subject: [PATCH] Add _binary_exists and use in github-cli completion gh was also used as an git alias, and caused _command_exists to not fail as expected --- completion/available/github-cli.completion.bash | 2 +- lib/helpers.bash | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/completion/available/github-cli.completion.bash b/completion/available/github-cli.completion.bash index 2fb3d370..7b7c9fa0 100644 --- a/completion/available/github-cli.completion.bash +++ b/completion/available/github-cli.completion.bash @@ -2,7 +2,7 @@ cite "about-completion" about-completion "GitHub CLI completion" -if _command_exists gh; then +if _binary_exists gh; then if _command_exists brew; then _log_warning "You don't need github-cli completion enabled if you have system completion enabled" fi diff --git a/lib/helpers.bash b/lib/helpers.bash index 8917ed50..a709d507 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -26,6 +26,17 @@ function _command_exists () type "$1" &> /dev/null || (_log_warning "$msg" && return 1) ; } +function _binary_exists () +{ + _about 'checks for existence of a binary' + _param '1: binary to check' + _param '2: (optional) log message to include when binary not found' + _example '$ _binary_exists ls && echo exists' + _group 'lib' + local msg="${2:-Binary '$1' does not exist!}" + type -P "$1" &> /dev/null || (_log_warning "$msg" && return 1) ; +} + function _make_reload_alias() { echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}" }