diff --git a/local/bin/x-have b/local/bin/x-have new file mode 100755 index 0000000..2a986a0 --- /dev/null +++ b/local/bin/x-have @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# Returns which status +which -s "$1" >&/dev/null + +if [ $? -eq 0 ]; then + echo 0 +else + echo 1 +fi + diff --git a/scripts/install-cargo-packages.sh b/scripts/install-cargo-packages.sh index 1c360e6..d1641dd 100755 --- a/scripts/install-cargo-packages.sh +++ b/scripts/install-cargo-packages.sh @@ -6,7 +6,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" msg "Starting to install rust/cargo packages" -! have cargo && { +[[ $(x-have "cargo") == "1" ]] && { msg "cargo could not be found. installing cargo with rustup.rs" curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path } diff --git a/scripts/install-cheat-purebashbible.sh b/scripts/install-cheat-purebashbible.sh index 9c1567a..6332790 100755 --- a/scripts/install-cheat-purebashbible.sh +++ b/scripts/install-cheat-purebashbible.sh @@ -6,7 +6,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" PBB_REQUIRED_TOOLS=(git cheat) for t in ${PBB_REQUIRED_TOOLS[@]}; do - ! have "$t" && echo "(!) $t is missing, can't continue..." && exit 1 + [[ $(x-have "$t") == "1" ]] && echo "(!) $t is missing, can't continue..." && exit 1 done PBB_GIT="https://github.com/dylanaraps/pure-bash-bible.git" diff --git a/scripts/install-cheat-tldr.sh b/scripts/install-cheat-tldr.sh index 0887d2a..2a9b86c 100755 --- a/scripts/install-cheat-tldr.sh +++ b/scripts/install-cheat-tldr.sh @@ -6,7 +6,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" TLDR_REQUIRED_TOOLS=(git cheat) for t in ${TLDR_REQUIRED_TOOLS[@]}; do - ! have "$t" && echo "(!) $t is missing, can't continue..." && exit 1 + [[ $(x-have "$t") == "1" ]] && echo "(!) $t is missing, can't continue..." && exit 1 done TLDR_GIT="https://github.com/tldr-pages/tldr.git" diff --git a/scripts/install-composer.sh b/scripts/install-composer.sh index ba5ce7f..1d2458e 100755 --- a/scripts/install-composer.sh +++ b/scripts/install-composer.sh @@ -4,7 +4,7 @@ # shellcheck source="shared.sh" source "$HOME/.dotfiles/scripts/shared.sh" -! have php && msg_err "PHP Not Available, cannot install composer" && exit 0 +[[ $(x-have "php") == "1" ]] && msg_err "PHP Not Available, cannot install composer" && exit 0 EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" diff --git a/scripts/install-gh-extensions.sh b/scripts/install-gh-extensions.sh index f40be35..3b89940 100755 --- a/scripts/install-gh-extensions.sh +++ b/scripts/install-gh-extensions.sh @@ -6,7 +6,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" msg_run "Installing gh (GitHub Client) extensions" -! have gh \ +[[ $(x-have "gh") == "1" ]] \ && msg_err "gh (GitHub Client) could not be found, please install it first" \ && exit 0 diff --git a/scripts/install-git-crypt.sh b/scripts/install-git-crypt.sh index 6fe4923..71f0e6d 100755 --- a/scripts/install-git-crypt.sh +++ b/scripts/install-git-crypt.sh @@ -8,7 +8,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" msg_run "Installing git-crypt" -! have git-crypt && { +[[ $(x-have "git-crypt") == "1" ]] && { REPO_URL="https://github.com/AGWA/git-crypt.git" CHECK_PATH="${XDG_BIN_HOME}/git-crypt" diff --git a/scripts/install-go-packages.sh b/scripts/install-go-packages.sh index d740e3e..a8c51d5 100755 --- a/scripts/install-go-packages.sh +++ b/scripts/install-go-packages.sh @@ -6,7 +6,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" msg_run "Installing go packages" -! have go && msg "go hasn't been installed yet." && exit 0 +[[ $(x-have "go") == "1" ]] && msg "go hasn't been installed yet." && exit 0 packages=( # A shell parser, formatter, and interpreter with bash support; includes shfmt diff --git a/scripts/install-neofetch.sh b/scripts/install-neofetch.sh index 34743c1..0aa01ce 100755 --- a/scripts/install-neofetch.sh +++ b/scripts/install-neofetch.sh @@ -11,7 +11,7 @@ NEOFETCH_URL="${NEOFETCH_REPO}/archive/refs/tags/${NEOFETCH_VERSION}.tar.gz" NEOFETCH_TEMP="/tmp/neofetch" NEOFETCH_INSTALL_PREFIX="$HOME/.local" -have neofetch || { +[[ $(x-have "neofetch") == "1" ]] && { LC_ALL=C mkdir -p "$NEOFETCH_TEMP" "$NEOFETCH_INSTALL_PREFIX" diff --git a/scripts/install-npm-packages.sh b/scripts/install-npm-packages.sh index c6c58d8..20df8bb 100755 --- a/scripts/install-npm-packages.sh +++ b/scripts/install-npm-packages.sh @@ -6,7 +6,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" msg "Starting to install npm packages" -! have npm && msg_err "npm could not be found." && exit 0 +[[ $(x-have "npm") == "1" ]] && msg_err "npm could not be found." && exit 0 packages=( # This is a tool to check if your files consider your .editorconfig rules. diff --git a/scripts/install-ntfy.sh b/scripts/install-ntfy.sh index ce40d0b..cda813a 100755 --- a/scripts/install-ntfy.sh +++ b/scripts/install-ntfy.sh @@ -6,7 +6,7 @@ source "$HOME/.dotfiles/scripts/shared.sh" set -e -have ntfy && msg "ntfy already installed" && exit 0 +[[ $(x-have "ntfy") == "0" ]] && msg "ntfy already installed" && exit 0 case $(dfm check arch) in Linux) diff --git a/scripts/install-pip-packages.sh b/scripts/install-pip-packages.sh index 14b7305..632588e 100755 --- a/scripts/install-pip-packages.sh +++ b/scripts/install-pip-packages.sh @@ -6,8 +6,8 @@ source "$HOME/.dotfiles/scripts/shared.sh" msg "Starting to install pip packages" -! have python3 && { - msg_err "Could not find python3, something really terrible is going on." && exit 1 +[[ $(x-have "python3") == "1" ]] && { + msg_err "Could not find python3, something really weird is going on." && exit 1 } packages=( diff --git a/scripts/shared.sh b/scripts/shared.sh index 8eaf3c5..46142e4 100755 --- a/scripts/shared.sh +++ b/scripts/shared.sh @@ -92,7 +92,7 @@ function have_command # usage: have php && php -v function have { - bkt -- which -s "$1" >&/dev/null + bkt -- which "$1" >&/dev/null } function brew_installed