-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,3 +272,60 @@ 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 | ||
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 | ||
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 $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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe there is some magic going on here I don't understand but shouldn't you use the same logic as above: Maybe this is the reason why fish is not working for you? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the variable does not have a backslash before it it gets interpreted by the shell, in that code it just expands BREW_ROOT then writes the file, not the other way around There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah you are correct, it was quite late yesterday for me ;)
|
||
[ -f "\$HB_CNF_HANDLER" ] && source "\$HB_CNF_HANDLER" | ||
export BREW_COMMAND_NOT_FOUND=1 | ||
fi | ||
tulilirockz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
EOF | ||
pkexec tee $FISH_PATH > /dev/null <<EOF | ||
set HB_CNF_HANDLER "${BREW_ROOT}/Library/Taps/homebrew/homebrew-command-not-found/handler.fish" | ||
tulilirockz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if test -f \$HB_CNF_HANDLER && test \$BREW_COMMAND_NOT_FOUND != 1 | ||
set BREW_COMMAND_NOT_FOUND 1 | ||
source \$HB_CNF_HANDLER | ||
end | ||
EOF | ||
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 $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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure Homebrew is installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, placed it wrong LOL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this comment I actually meant that the first sentence in the echo is wrong, isn't it? ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OH! I didnt see that typo till now! Great catch!