-
-
Notifications
You must be signed in to change notification settings - Fork 289
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
Add shell completion for zsh #1166 #1216
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#compdef brew | ||
#autoload | ||
|
||
__brew_bundle_commands() { | ||
local -a commands | ||
commands=( | ||
'-h:Show help' | ||
'--help:Show help' | ||
'install:Install and upgrade (by default) all dependencies from the Brewfile' | ||
'dump:Write all installed casks/formulae/images/taps into a Brewfile in the current directory' | ||
'cleanup:Uninstall all dependencies not listed from the Brewfile' | ||
'check:Check if all dependencies are installed from the Brewfile' | ||
'list:List all dependencies present in the Brewfile' | ||
'exec:Run an external command in an isolated build environment based on the Brewfile dependencies' | ||
) | ||
_describe -t commands 'commands' commands | ||
} | ||
|
||
_brew_bundle_install() { | ||
_arguments \ | ||
'--file[read the Brewfile from this location. Use --file=- to pipe to stdin/stdout]' \ | ||
'--global[read the Brewfile from ~/.Brewfile]' \ | ||
'-v[print output from commands as they are run]' \ | ||
'--verbose[print output from commands as they are run]' \ | ||
"--no-upgrade[don't run brew upgrade on outdated dependencies]" \ | ||
"--no-lock[don't output a Brewfile.lock.json]" \ | ||
'--cleanup[perform cleanup operation, same as running cleanup --force]' \ | ||
'--zap[cleanup casks using the zap command instead of uninstall]' | ||
} | ||
|
||
_brew_bundle_dump() { | ||
_arguments \ | ||
'--file[read the Brewfile from this location. Use --file=- to pipe to stdin/stdout]' \ | ||
'--global[read the Brewfile from ~/.Brewfile]' \ | ||
'-f[overwrite an existing Brewfile]' \ | ||
'--force[overwrite an existing Brewfile]' \ | ||
'--describe[add a description comment above each line, unless the dependency does not have a description]' \ | ||
"--no-restart[don't add restart_service to formula lines]" | ||
} | ||
|
||
_brew_bundle_cleanup() { | ||
_arguments \ | ||
'--file[read the Brewfile from this location. Use --file=- to pipe to stdin/stdout]' \ | ||
'--global[read the Brewfile from ~/.Brewfile]' \ | ||
'-f[actually perform cleanup operations]' \ | ||
'--force[actually perform cleanup operations]' \ | ||
'--zap[cleanup casks using the zap command instead of uninstall]' | ||
} | ||
|
||
_brew_bundle_check() { | ||
_arguments \ | ||
'--file[read the Brewfile from this location. Use --file=- to pipe to stdin/stdout]' \ | ||
'--global[read the Brewfile from ~/.Brewfile]' | ||
} | ||
|
||
_brew_bundle_list() { | ||
_arguments \ | ||
'--file[read the Brewfile from this location. Use --file=- to pipe to stdin/stdout]' \ | ||
'--global[read the Brewfile from ~/.Brewfile]' \ | ||
'--all[list all dependencies]' \ | ||
'--formula[list Homebrew dependencies]' \ | ||
'--brews[list Homebrew dependencies]' \ | ||
'--cask[list Homebrew Cask dependencies]' \ | ||
'--casks[list Homebrew Cask dependencies]' \ | ||
'--tap[list tap dependencies]' \ | ||
'--taps[list tap dependencies]' \ | ||
'--mas[list Mac App Store dependencies]' \ | ||
'--whalebrew[list Whalebrew dependencies]' \ | ||
'--vscode[list VSCode extensions]' | ||
} | ||
|
||
_brew_bundle_exec() { | ||
_arguments \ | ||
'--file[read the Brewfile from this location. Use --file=- to pipe to stdin/stdout]' \ | ||
'--global[read the Brewfile from ~/.Brewfile]' | ||
} | ||
|
||
_brew_bundle_() { | ||
return 1 | ||
} | ||
|
||
_brew_bundle() { | ||
local state line ret=1 | ||
|
||
_arguments -C \ | ||
'1: :->command' \ | ||
'*::arg:->args' && return 0 | ||
|
||
case $state in | ||
command) | ||
__brew_bundle_commands ;; | ||
args) | ||
local command completion_func | ||
command="${line[1]}" | ||
completion_func="_brew_bundle_${command//-/_}" | ||
|
||
_call_function ret "${completion_func}" && return ret | ||
|
||
_message "a completion function is not defined for brew bundle ${command}" | ||
return 1 | ||
;; | ||
esac | ||
} | ||
|
||
_brew_bundle "$@" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I wonder if there's any way to rely on any of the Homebrew/brew code to autogenerate some/all of this or at least have CI to ensure it's kept in sync?
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.
I didn't research that :c
I know there are some tools to automate this script creation in golang, but not sure for ruby
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.
No worries, I'll try to help! Check out:
https://github.com/Homebrew/brew/blob/a56a2707075a10827b4c49b3cc51cae7bb94c2d6/completions/zsh/_brew#L4-L6
and
https://github.com/Homebrew/brew/blob/a56a2707075a10827b4c49b3cc51cae7bb94c2d6/Library/Homebrew/completions.rb
which you could maybe use for auto-generation?
Don't worry if you can't handle the e.g. GitHub Actions side: I can help with all that.
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.
Well, i'm not good at ruby (actually, it's my first try), but after some research of given code, i think i can make similar for
brew bundle
.It requires some refactoring and i think, i would make it, if may
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.
@tony-sol just wanted to check how things are going and what you're thinking! Thanks again for the PR!
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.
@MikeMcQuaid sorry, i've been unlucky with free time lately :c
i remember about this PR, but can't say, when could continue work on it :c
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.
@tony-sol No worries! Just saw the rebase and wanted to check!