diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 40f5875f9f..e232eb79ba 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -34,9 +34,9 @@ module Homebrew description: "Show the versions of pinned formulae, or only the specified (pinned) "\ "formulae if are provided. See also `pin`, `unpin`." switch "--formula", "--formulae", - description: "List only formulae." + description: "List only formulae. `This is the default action on non TTY.`" switch "--cask", "--casks", - description: "List only casks." + description: "List only casks, or if provided." # passed through to ls switch "-1", description: "Force output to be one entry per line. " \ @@ -87,7 +87,13 @@ module Homebrew ls_args << "-r" if args.r? ls_args << "-t" if args.t? - safe_system "ls", *ls_args, HOMEBREW_CELLAR + if !$stdout.tty? && !args.formula? + odeprecated "`brew list` to only list formulae", "`brew list --formula`" + safe_system "ls", *ls_args, HOMEBREW_CELLAR + else + safe_system "ls", *ls_args, HOMEBREW_CELLAR + list_casks(args: args) unless args.formula? + end end elsif args.verbose? || !$stdout.tty? system_command! "find", args: args.named.to_kegs.map(&:to_s) + %w[-not -type d -print], print_stdout: true diff --git a/Library/Homebrew/test/cmd/list_spec.rb b/Library/Homebrew/test/cmd/list_spec.rb index ff438b222b..a06fa06156 100644 --- a/Library/Homebrew/test/cmd/list_spec.rb +++ b/Library/Homebrew/test/cmd/list_spec.rb @@ -15,7 +15,7 @@ describe "brew list", :integration_test do (HOMEBREW_CELLAR/f/"1.0/somedir").mkpath end - expect { brew "list" } + expect { brew "list", "--formula" } .to output("#{formulae.join("\n")}\n").to_stdout .and not_to_output.to_stderr .and be_a_success diff --git a/completions/zsh/_brew b/completions/zsh/_brew index e0f635b248..1ff67fac63 100644 --- a/completions/zsh/_brew +++ b/completions/zsh/_brew @@ -62,10 +62,17 @@ __brew_formulae() { __brew_installed_formulae() { local -a formulae - formulae=($(brew list)) + formulae=($(brew list --formula)) _describe -t formulae 'installed formulae' formulae } +__brew_installed_casks() { + local -a list + local expl + list=( $(brew list --cask) ) + _wanted list expl 'installed casks' compadd -a list +} + __brew_outdated_formulae() { local -a formulae formulae=($(brew outdated)) @@ -493,11 +500,12 @@ _brew_linkage() { # brew list, ls [--full-name]: # brew list, ls --unbrewed: # brew list, ls [--versions [--multiple]] [--pinned] [formulae]: -# brew list, ls --cask: +# brew list, ls [--cask|--formula]: _brew_list() { local state _arguments \ - formulae \ + '--formula[list install formulae]' \ '--full-name[print formulae with fully-qualified names]' \ '--unbrewed[files in brew --prefix not controlled by brew]' \ '--pinned[list all versions of pinned formulae]' \ @@ -575,7 +583,7 @@ _brew_outdated() { '--fetch-HEAD[detect if the HEAD installation of the formula is outdated]' \ - cask \ '--cask[list outdated Casks]' \ - '--greedy[also list Casks with auto_updates or version \:latest]' \ + '--greedy[also list Casks with auto_updates or version \:latest]' } # brew pin formulae: diff --git a/docs/Manpage.md b/docs/Manpage.md index 5f2770b4a5..3bd3c032d9 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -364,9 +364,9 @@ If *`formula`* is provided, summarise the paths within its current keg. * `--pinned`: Show the versions of pinned formulae, or only the specified (pinned) formulae if *`formula`* are provided. See also `pin`, `unpin`. * `--formula`: - List only formulae. + List only formulae. `This is the default action on non TTY.` * `--cask`: - List only casks. + List only casks, or *`cask`* if provided. * `-1`: Force output to be one entry per line. This is the default when output is not to a terminal. * `-l`: diff --git a/manpages/brew.1 b/manpages/brew.1 index d19a2c0a58..24b3607aab 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -533,11 +533,11 @@ Show the versions of pinned formulae, or only the specified (pinned) formulae if . .TP \fB\-\-formula\fR -List only formulae\. +List only formulae\. \fBThis is the default action on non TTY\.\fR . .TP \fB\-\-cask\fR -List only casks\. +List only casks, or \fIcask\fR if provided\. . .TP \fB\-1\fR