Skip to content

Commit

Permalink
fix(just): better logic + maintainability for brew-setup recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
tulilirockz committed Nov 13, 2024
1 parent dff8203 commit a46a709
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions just/bluefin-tools.just
Original file line number Diff line number Diff line change
Expand Up @@ -293,26 +293,28 @@ setup-brew-not-found ACTION="":
set -euo pipefail
BREW_BINARY=/home/linuxbrew/.linuxbrew/bin/brew
BREW_ROOT=${HOMEBREW_REPOSITORY:-$($BREW_BINARY --repository)}
if ! $BREW_BINARY -h > /dev/null; then
echo "Make sure Homebrew is first. Check journalctl -e -u brew-setup.service"
exit
fi
BREW_ROOT=${HOMEBREW_REPOSITORY:-$($BREW_BINARY --repository)}
FISH_PATH="/etc/fish/conf.d/brew-command-not-found.fish"
BASH_PATH="/etc/profile.d/brew-command-not-found.sh"
if [[ "${OPTION,,}" =~ ^enable ]]; then
$BREW_BINARY tap homebrew/command-not-found
pkexec tee /etc/profile.d/brew-command-not-found.sh > /dev/null <<EOF
pkexec tee $BASH_PATH > /dev/null <<EOF
# Check for interactive bash or zsh and that we haven't already been sourced
if [[ -d /home/linuxbrew/.linuxbrew && \$- == *i* && BREW_COMMAND_NOT_FOUND != 1 ]] ; then
HB_CNF_HANDLER="${BREW_ROOT}/Library/Taps/homebrew/homebrew-command-not-found/handler.sh"
[ -f "\$HB_CNF_HANDLER" ] && source "\$HB_CNF_HANDLER"
export BREW_COMMAND_NOT_FOUND=1
fi
EOF
pkexec tee /etc/fish/conf.d/brew-command-not-found.fish > /dev/null <<EOF
pkexec tee $FISH_PATH > /dev/null <<EOF
set HB_CNF_HANDLER "${BREW_ROOT}/Library/Taps/homebrew/homebrew-command-not-found/handler.fish"
if test -f \$HB_CNF_HANDLER
set BREW_COMMAND_NOT_FOUND=1
if test -f \$HB_CNF_HANDLER && test \$BREW_COMMAND_NOT_FOUND != 1
set BREW_COMMAND_NOT_FOUND 1
source \$HB_CNF_HANDLER
end
EOF
Expand All @@ -322,8 +324,8 @@ setup-brew-not-found ACTION="":
if [[ "${OPTION,,}" =~ ^disable ]]; then
$BREW_BINARY untap homebrew/command-not-found
FILES_TO_BE_REMOVED=()
[ -f /etc/profile.d/brew-command-not-found.sh ] && FILES_TO_BE_REMOVED+=("/etc/profile.d/brew-command-not-found.sh")
[ -f /etc/fish/conf.d/brew-command-not-found.fish ] && FILES_TO_BE_REMOVED+=("/etc/fish/conf.d/brew-command-not-found.fish")
[ -f $BASH_PATH ] && FILES_TO_BE_REMOVED+=("$BASH_PATH")
[ -f $FISH_PATH ] && FILES_TO_BE_REMOVED+=("$FISH_PATH")
pkexec rm -f "${FILES_TO_BE_REMOVED[@]}"
echo "Brew command-not-found has been ${b}${red}disabled${n}"
fi

0 comments on commit a46a709

Please sign in to comment.