Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(just): add brew-command-not-found setup #1874

Merged
merged 5 commits into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions just/bluefin-apps.just
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,54 @@ install-k8s-dev-tools:
#!/usr/bin/bash
echo "Adding Kubernetes command line tools..."
brew bundle --file /usr/share/ublue-os/homebrew/kubernetes.Brewfile

# Set up command-not-found for Homebrew
[group('Apps')]
setup-brew-not-found ACTION="":
#!/usr/bin/env bash
source /usr/lib/ujust/ujust.sh

OPTION={{ ACTION }}
if [ "$OPTION" == "help" ]; then
echo "Usage: ujust setup-brew-not-found <option>"
echo " <option>: Specify the quick option to skip the prompt"
echo " Use 'enable' to select Enable Brew Not Found"
echo " Use 'disable' to select Disable Brew Not Found"
exit 0
elif [ "$OPTION" == "" ]; then
echo "${bold}Brew command-not-found Setup${normal}"
OPTION=$(Choose "Enable Brew command-not-found" "Disable Brew command-not-found")
fi

set -euo pipefail

BREW_BINARY=/home/linuxbrew/.linuxbrew/bin/brew
HOMEBREW_REPOSITORY=${HOMEBREW_REPOSITORY:-$($BREW_BINARY --repository)}
if ! $BREW_BINARY -h > /dev/null; then
echo "Make sure Homebrew is installed first. Check journalctl -e -u brew-setup.service"
exit
fi

if [[ "${OPTION,,}" =~ ^enable ]]; then
$BREW_BINARY tap homebrew/command-not-found
pkexec tee /etc/profile.d/brew-command-not-found.sh > /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="${HOMEBREW_REPOSITORY}/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
# Necessary for fish since just having a script sourcing it does not work
pkexec ln -sf "${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-command-not-found/handler.fish" /etc/fish/conf.d/brew-cnf-handler.fish
echo "Brew command-not-found has been ${b}${green}enabled${n}"
fi

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")
pkexec rm -f "${FILES_TO_BE_REMOVED[@]}"
echo "Brew command-not-found has been ${b}${red}disabled${n}"
fi