Skip to content

Commit

Permalink
Merge pull request #158 from samford/brew-style-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMcQuaid authored Jun 12, 2024
2 parents 51be56c + 368b08e commit a7b85d2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cmd/which-formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class WhichFormulaCmd < AbstractCommand
Show which formula(e) provides the given command.
EOS
switch "--explain",
description: "Output explanation of how to get <command> by installing one of the providing formulae."
description: "Output explanation of how to get <command> by installing one of the providing formulae."
named_args :command, min: 1
end

Expand Down
20 changes: 10 additions & 10 deletions cmd/which-update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ class WhichUpdateCmd < AbstractCommand
Database update for `brew which-formula`.
EOS
switch "--stats",
description: "Print statistics about the database contents (number of commands and formulae, " \
description: "Print statistics about the database contents (number of commands and formulae, " \
"list of missing formulae)."
switch "--commit",
description: "Commit the changes using `git`."
description: "Commit the changes using `git`."
switch "--update-existing",
description: "Update database entries with outdated formula versions."
description: "Update database entries with outdated formula versions."
switch "--install-missing",
description: "Install and update formulae that are missing from the database and don't have bottles."
description: "Install and update formulae that are missing from the database and don't have bottles."
switch "--eval-all",
description: "Evaluate all installed taps, rather than just the core tap."
description: "Evaluate all installed taps, rather than just the core tap."
flag "--max-downloads=",
description: "Specify a maximum number of formulae to download and update."
description: "Specify a maximum number of formulae to download and update."
conflicts "--stats", "--commit"
conflicts "--stats", "--install-missing"
conflicts "--stats", "--update-existing"
Expand All @@ -34,12 +34,12 @@ def run
if args.stats?
Homebrew::WhichUpdate.stats source: args.named.first
else
Homebrew::WhichUpdate.update_and_save! source: args.named.first,
commit: args.commit?,
Homebrew::WhichUpdate.update_and_save! source: args.named.first,
commit: args.commit?,
update_existing: args.update_existing?,
install_missing: args.install_missing?,
max_downloads: args.max_downloads,
eval_all: args.eval_all?
max_downloads: args.max_downloads,
eval_all: args.eval_all?
end
end
end
Expand Down
77 changes: 41 additions & 36 deletions handler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,56 @@
# Version: 0.2.0
#

if ! which brew > /dev/null; then return; fi
if ! which brew >/dev/null; then return; fi

homebrew_command_not_found_handle() {

local cmd="$1"
local cmd="$1"

# The code below is based off this Linux Journal article:
# http://www.linuxjournal.com/content/bash-command-not-found
# The code below is based off this Linux Journal article:
# http://www.linuxjournal.com/content/bash-command-not-found

# do not run when inside Midnight Commander or within a Pipe, except if CI
if test -z "$CONTINUOUS_INTEGRATION" && test -n "$MC_SID" -o ! -t 1 ; then
[ -n "$BASH_VERSION" ] && \
TEXTDOMAIN=command-not-found echo $"$cmd: command not found"
# Zsh versions 5.3 and above don't print this for us.
[ -n "$ZSH_VERSION" ] && [[ "$ZSH_VERSION" > "5.2" ]] && \
echo "zsh: command not found: $cmd" >&2
return 127
fi
# do not run when inside Midnight Commander or within a Pipe, except if CI
if test -z "${CONTINUOUS_INTEGRATION}" && test -n "${MC_SID}" -o ! -t 1
then
[[ -n "${BASH_VERSION}" ]] &&
TEXTDOMAIN=command-not-found echo $"${cmd}: command not found"
# Zsh versions 5.3 and above don't print this for us.
[[ -n "${ZSH_VERSION}" ]] && [[ "${ZSH_VERSION}" > "5.2" ]] &&
echo "zsh: command not found: ${cmd}" >&2
return 127
fi

if [ "$cmd" != "-h" ] && [ "$cmd" != "--help" ] && [ "$cmd" != "--usage" ] && [ "$cmd" != "-?" ]; then
local txt="$(brew which-formula --explain $cmd 2>/dev/null)"
fi
if [[ "${cmd}" != "-h" ]] && [[ "${cmd}" != "--help" ]] && [[ "${cmd}" != "--usage" ]] && [[ "${cmd}" != "-?" ]]
then
local txt="$(brew which-formula --explain "${cmd}" 2>/dev/null)"
fi

if [ -z "$txt" ]; then
[ -n "$BASH_VERSION" ] && \
TEXTDOMAIN=command-not-found echo $"$cmd: command not found"
if [[ -z "${txt}" ]]
then
[[ -n "${BASH_VERSION}" ]] &&
TEXTDOMAIN=command-not-found echo $"${cmd}: command not found"

# Zsh versions 5.3 and above don't print this for us.
[ -n "$ZSH_VERSION" ] && [[ "$ZSH_VERSION" > "5.2" ]] && \
echo "zsh: command not found: $cmd" >&2
else
echo "$txt"
fi
# Zsh versions 5.3 and above don't print this for us.
[[ -n "${ZSH_VERSION}" ]] && [[ "${ZSH_VERSION}" > "5.2" ]] &&
echo "zsh: command not found: ${cmd}" >&2
else
echo "${txt}"
fi

return 127
return 127
}

if [ -n "$BASH_VERSION" ]; then
command_not_found_handle() {
homebrew_command_not_found_handle $*
return $?
}
elif [ -n "$ZSH_VERSION" ]; then
command_not_found_handler() {
homebrew_command_not_found_handle $*
return $?
}
if [[ -n "${BASH_VERSION}" ]]
then
command_not_found_handle() {
homebrew_command_not_found_handle "$*"
return $?
}
elif [[ -n "${ZSH_VERSION}" ]]
then
command_not_found_handler() {
homebrew_command_not_found_handle "$*"
return $?
}
fi

0 comments on commit a7b85d2

Please sign in to comment.