From 8cc3e0afd2708f0b72d1052a2619494d2edcad8d Mon Sep 17 00:00:00 2001 From: Marley Rae Date: Mon, 22 Jan 2024 21:01:13 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Make=20Homebrew=20install=20stuff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git/install.sh | 9 ++++++ homebrew/brew_utils.sh | 70 ++++++++++++++++++++++++++++++++++++++++ homebrew/install_once.sh | 11 ------- zsh/install.sh | 5 +-- 4 files changed, 82 insertions(+), 13 deletions(-) create mode 100755 git/install.sh create mode 100644 homebrew/brew_utils.sh delete mode 100644 homebrew/install_once.sh diff --git a/git/install.sh b/git/install.sh new file mode 100755 index 0000000..5738159 --- /dev/null +++ b/git/install.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# vim:set ft=bash: + +cd "$(dirname "${BASH_SOURCE[0]}")" \ + && . "../homebrew/brew_utils.sh" + +brew_install "Git" "git" +brew_install "Github CLI" "gh" +brew_install "Gitmoji" "gitmoji" diff --git a/homebrew/brew_utils.sh b/homebrew/brew_utils.sh new file mode 100644 index 0000000..e6c931c --- /dev/null +++ b/homebrew/brew_utils.sh @@ -0,0 +1,70 @@ +#!/user/bin/env bash + +cd "$(dirname "${BASH_SOURCE[0]}")" \ + && . "../script/utils.sh" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +brew_prefix() +{ + local path="" + + if path="$(brew --prefix 2>/dev/null)"; then + printf "%s" "$path" + return 0 + else + print_error "Homebrew (get prefix)" + return 1 + fi +} + +brew_tap() +{ + brew tap "$1" &>/dev/null +} + +brew_update() +{ + execute "brew update" "Homebrew (update)" +} + +brew_upgrade() +{ + execute "brew upgrade" "Homebrew (upgrade)" +} + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +brew_install() +{ + declare -r FORMULA_READABLE_NAME="$1" + declare -r FORMULA="$2" + declare -r ARGUMENTS="$3" + declare -r TAP_VALUE="$4" + + # Check that Homebrew is installed. + + if ! cmd_exists "brew"; then + print_error "$FORMULA_READABLE_NAME ('Homebrew' is not installed)" + return 1 + fi + + # If 'brew tap' needs to be executed, check if it executed correctly. + + if [[ -n "$TAP_VALUE" ]]; then + if ! brew_tap "$TAP_VALUE"; then + print_error "$FORMULA_READABLE_NAME ('brew tap $TAP_VALUE' failed)" + return 1 + fi + fi + + # Install the specified formula. + + # shellcheck disable=SC2086 + if brew list "$FORMULA" &>/dev/null; then + print_success "$FORMULA_READABLE_NAME" + else + execute "brew install $FORMULA $ARGUMENTS" \ + "$FORMULA_READABLE_NAME" + fi +} diff --git a/homebrew/install_once.sh b/homebrew/install_once.sh deleted file mode 100644 index e70a02d..0000000 --- a/homebrew/install_once.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/user/bin/env bash -# vim:set ft=bash: - -install_once() -{ - if brew ls --versions "$1"; then - brew upgrade "$1" - else - brew install "$1" - fi -} diff --git a/zsh/install.sh b/zsh/install.sh index 016a0a9..2dd4cb2 100755 --- a/zsh/install.sh +++ b/zsh/install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash # vim:set ft=bash: -source $DOT/homebrew/install_once.sh +cd "$(dirname "${BASH_SOURCE[0]}")" \ + && . "../homebrew/brew_utils.sh" -install_once starship +brew_install "Starship Prompt" "starship"