From 98c968ea2f5e9239431dcf4ce5a52793fff77ee0 Mon Sep 17 00:00:00 2001 From: Kid Date: Fri, 25 Dec 2020 22:32:48 +0800 Subject: [PATCH 1/5] Add brew casks command --- Library/Homebrew/brew.sh | 1 + Library/Homebrew/cmd/casks.sh | 29 ++++++++++++++++++++++++++ completions/bash/brew | 7 ++----- completions/fish/brew.fish | 2 +- completions/internal_commands_list.txt | 1 + completions/zsh/_brew_cask | 2 +- docs/Manpage.md | 4 ++++ manpages/brew.1 | 3 +++ 8 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 Library/Homebrew/cmd/casks.sh diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 25ac493ffe..9442995876 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -55,6 +55,7 @@ case "$*" in --cache) echo "$HOMEBREW_CACHE"; exit 0 ;; shellenv) source "$HOMEBREW_LIBRARY/Homebrew/cmd/shellenv.sh"; homebrew-shellenv; exit 0 ;; formulae) source "$HOMEBREW_LIBRARY/Homebrew/cmd/formulae.sh"; homebrew-formulae; exit 0 ;; + casks) source "$HOMEBREW_LIBRARY/Homebrew/cmd/casks.sh"; homebrew-casks; exit 0 ;; esac ##### diff --git a/Library/Homebrew/cmd/casks.sh b/Library/Homebrew/cmd/casks.sh new file mode 100644 index 0000000000..64113d1f4a --- /dev/null +++ b/Library/Homebrew/cmd/casks.sh @@ -0,0 +1,29 @@ +#: * `casks` +#: +#: List all locally installable casks including short names. +#: + +homebrew-casks() { + local casks + local sed_extended_regex_flag + + if [[ -n "$HOMEBREW_MACOS" ]]; then + sed_extended_regex_flag="-E" + else + sed_extended_regex_flag="-r" + fi + + casks="$( \ + find "$HOMEBREW_REPOSITORY/Library/Taps" \ + -maxdepth 4 -path '*/Casks/*.rb' | \ + sed "$sed_extended_regex_flag" \ + -e 's/\.rb//g' \ + -e 's_.*/Taps/(.*)/(home|linux)brew-_\1/_' \ + -e 's|/Casks/|/|' \ + )" + local shortnames + shortnames="$(echo "$casks" | cut -d "/" -f 3)" + echo -e "$casks\n$shortnames" | \ + grep -v '^homebrew/cask' | \ + sort -uf +} diff --git a/completions/bash/brew b/completions/bash/brew index 887acc5ddc..20004e3040 100644 --- a/completions/bash/brew +++ b/completions/bash/brew @@ -656,12 +656,9 @@ __brew_caskcomp () __brew_cask_complete_formulae () { local cur="${COMP_WORDS[COMP_CWORD]}" - local lib=$(brew --repository)/Library - local taps=${lib}/Taps - local casks=${lib}/Taps/homebrew/homebrew-cask/Casks - local ff=$(\ls ${casks} 2>/dev/null | \sed 's/\.rb//g') + local casks=$(brew casks) - COMPREPLY=($(compgen -W "$ff" -- "$cur")) + COMPREPLY=($(compgen -W "$casks" -- "$cur")) } __brew_cask_complete_installed () diff --git a/completions/fish/brew.fish b/completions/fish/brew.fish index c45e595485..016faea1b1 100644 --- a/completions/fish/brew.fish +++ b/completions/fish/brew.fish @@ -206,7 +206,7 @@ function __fish_brew_suggest_casks_outdated -d "Lists outdated casks with the in end function __fish_brew_suggest_casks_all -d "Lists locally available casks" - brew search --cask + brew casks end diff --git a/completions/internal_commands_list.txt b/completions/internal_commands_list.txt index c9c4fbf6aa..4bee0c82c3 100644 --- a/completions/internal_commands_list.txt +++ b/completions/internal_commands_list.txt @@ -20,6 +20,7 @@ bump-formula-pr bump-revision bump-unversioned-casks cask +casks cat cleanup command diff --git a/completions/zsh/_brew_cask b/completions/zsh/_brew_cask index 81c8a3fee4..734be2e42b 100644 --- a/completions/zsh/_brew_cask +++ b/completions/zsh/_brew_cask @@ -18,7 +18,7 @@ __brew_all_casks() { local comp_cachename=brew_casks if ! _retrieve_cache $comp_cachename; then - list=( $(brew search --cask) ) + list=( $(brew casks) ) _store_cache $comp_cachename list fi diff --git a/docs/Manpage.md b/docs/Manpage.md index 946d3c0a15..f11b9c6b54 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -65,6 +65,10 @@ Uninstall formulae that were only installed as a dependency of another formula a * `-n`, `--dry-run`: List what would be uninstalled, but do not actually uninstall anything. +### `casks` + +List all locally installable casks including short names. + ### `cleanup` [*`options`*] [*`formula`*|*`cask`*] Remove stale lock files and outdated downloads for all formulae and casks, diff --git a/manpages/brew.1 b/manpages/brew.1 index 0284bb679f..a32d11757e 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -60,6 +60,9 @@ Uninstall formulae that were only installed as a dependency of another formula a \fB\-n\fR, \fB\-\-dry\-run\fR List what would be uninstalled, but do not actually uninstall anything\. . +.SS "\fBcasks\fR" +List all locally installable casks including short names\. +. .SS "\fBcleanup\fR [\fIoptions\fR] [\fIformula\fR|\fIcask\fR]" Remove stale lock files and outdated downloads for all formulae and casks, and remove old versions of installed formulae\. If arguments are specified, only do this for the given formulae and casks\. Removes all downloads more than 120 days old\. This can be adjusted with \fBHOMEBREW_CLEANUP_MAX_AGE_DAYS\fR\. . From 13389ca8c53fdf649d1f9b7b9ba7d38e31baa438 Mon Sep 17 00:00:00 2001 From: Kid Date: Fri, 8 Jan 2021 11:20:13 +0800 Subject: [PATCH 2/5] Linuxbrew won't have casks --- Library/Homebrew/cmd/casks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/casks.sh b/Library/Homebrew/cmd/casks.sh index 64113d1f4a..46050ee9b7 100644 --- a/Library/Homebrew/cmd/casks.sh +++ b/Library/Homebrew/cmd/casks.sh @@ -18,7 +18,7 @@ homebrew-casks() { -maxdepth 4 -path '*/Casks/*.rb' | \ sed "$sed_extended_regex_flag" \ -e 's/\.rb//g' \ - -e 's_.*/Taps/(.*)/(home|linux)brew-_\1/_' \ + -e 's_.*/Taps/(.*)/homebrew-_\1/_' \ -e 's|/Casks/|/|' \ )" local shortnames From c57b65fdb8e4abaf74e9e4197fa7237adff83090 Mon Sep 17 00:00:00 2001 From: Kid Date: Fri, 8 Jan 2021 17:36:38 +0800 Subject: [PATCH 3/5] Revert "Linuxbrew won't have casks" This reverts commit 13389ca8c53fdf649d1f9b7b9ba7d38e31baa438. In case we can extract a common function or stuff. --- Library/Homebrew/cmd/casks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/casks.sh b/Library/Homebrew/cmd/casks.sh index 46050ee9b7..64113d1f4a 100644 --- a/Library/Homebrew/cmd/casks.sh +++ b/Library/Homebrew/cmd/casks.sh @@ -18,7 +18,7 @@ homebrew-casks() { -maxdepth 4 -path '*/Casks/*.rb' | \ sed "$sed_extended_regex_flag" \ -e 's/\.rb//g' \ - -e 's_.*/Taps/(.*)/homebrew-_\1/_' \ + -e 's_.*/Taps/(.*)/(home|linux)brew-_\1/_' \ -e 's|/Casks/|/|' \ )" local shortnames From 9b9c0c8626025a9d108b8d3707afbafe212f288e Mon Sep 17 00:00:00 2001 From: Kid Date: Fri, 8 Jan 2021 18:04:51 +0800 Subject: [PATCH 4/5] Add homebrew-items --- Library/Homebrew/cmd/casks.sh | 25 +++-------------------- Library/Homebrew/cmd/formulae.sh | 33 +++--------------------------- Library/Homebrew/items.sh | 35 ++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 52 deletions(-) create mode 100644 Library/Homebrew/items.sh diff --git a/Library/Homebrew/cmd/casks.sh b/Library/Homebrew/cmd/casks.sh index 64113d1f4a..4a8d866f45 100644 --- a/Library/Homebrew/cmd/casks.sh +++ b/Library/Homebrew/cmd/casks.sh @@ -3,27 +3,8 @@ #: List all locally installable casks including short names. #: +source "$HOMEBREW_LIBRARY/Homebrew/items.sh" + homebrew-casks() { - local casks - local sed_extended_regex_flag - - if [[ -n "$HOMEBREW_MACOS" ]]; then - sed_extended_regex_flag="-E" - else - sed_extended_regex_flag="-r" - fi - - casks="$( \ - find "$HOMEBREW_REPOSITORY/Library/Taps" \ - -maxdepth 4 -path '*/Casks/*.rb' | \ - sed "$sed_extended_regex_flag" \ - -e 's/\.rb//g' \ - -e 's_.*/Taps/(.*)/(home|linux)brew-_\1/_' \ - -e 's|/Casks/|/|' \ - )" - local shortnames - shortnames="$(echo "$casks" | cut -d "/" -f 3)" - echo -e "$casks\n$shortnames" | \ - grep -v '^homebrew/cask' | \ - sort -uf + homebrew-items 'Formula' 's|/Casks/|/|' '^homebrew/cask' } diff --git a/Library/Homebrew/cmd/formulae.sh b/Library/Homebrew/cmd/formulae.sh index e2f803724d..eee27c9629 100644 --- a/Library/Homebrew/cmd/formulae.sh +++ b/Library/Homebrew/cmd/formulae.sh @@ -3,35 +3,8 @@ #: List all locally installable formulae including short names. #: +source "$HOMEBREW_LIBRARY/Homebrew/items.sh" + homebrew-formulae() { - local formulae - local sed_extended_regex_flag - - if [[ -n "$HOMEBREW_MACOS" ]]; then - sed_extended_regex_flag="-E" - else - sed_extended_regex_flag="-r" - fi - - formulae="$( \ - find "$HOMEBREW_REPOSITORY/Library/Taps" \ - -type d \( \ - -name Casks -o \ - -name cmd -o \ - -name .github -o \ - -name lib -o \ - -name spec -o \ - -name vendor \ - \) \ - -prune -false -o -name '*\.rb' | \ - sed "$sed_extended_regex_flag" \ - -e 's/\.rb//g' \ - -e 's_.*/Taps/(.*)/(home|linux)brew-_\1/_' \ - -e 's|/Formula/|/|' \ - )" - local shortnames - shortnames="$(echo "$formulae" | cut -d "/" -f 3)" - echo -e "$formulae\n$shortnames" | \ - grep -v '^homebrew/core' | \ - sort -uf + homebrew-items 'Casks' 's|/Formula/|/|' '^homebrew/core' } diff --git a/Library/Homebrew/items.sh b/Library/Homebrew/items.sh new file mode 100644 index 0000000000..6edf44dfc6 --- /dev/null +++ b/Library/Homebrew/items.sh @@ -0,0 +1,35 @@ +homebrew-items() { + local items + local sed_extended_regex_flag + local find_filter=$1 + local sed_filter=$2 + local grep_filter=$3 + + if [[ -n "$HOMEBREW_MACOS" ]]; then + sed_extended_regex_flag="-E" + else + sed_extended_regex_flag="-r" + fi + + items="$( \ + find "$HOMEBREW_REPOSITORY/Library/Taps" \ + -type d \( \ + -name $find_filter -o \ + -name cmd -o \ + -name .github -o \ + -name lib -o \ + -name spec -o \ + -name vendor \ + \) \ + -prune -false -o -name '*\.rb' | \ + sed "$sed_extended_regex_flag" \ + -e 's/\.rb//g' \ + -e 's_.*/Taps/(.*)/(home|linux)brew-_\1/_' \ + -e $sed_filter \ + )" + local shortnames + shortnames="$(echo "$items" | cut -d "/" -f 3)" + echo -e "$items\n$shortnames" | \ + grep -v $grep_filter | \ + sort -uf +} From de8e87c7d0f39af44232a6dc60d5db4ad2357390 Mon Sep 17 00:00:00 2001 From: Kid Date: Fri, 8 Jan 2021 18:10:25 +0800 Subject: [PATCH 5/5] Syntax fix --- Library/Homebrew/cmd/casks.sh | 2 ++ Library/Homebrew/cmd/formulae.sh | 2 ++ Library/Homebrew/items.sh | 6 +++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/casks.sh b/Library/Homebrew/cmd/casks.sh index 4a8d866f45..5aa207879b 100644 --- a/Library/Homebrew/cmd/casks.sh +++ b/Library/Homebrew/cmd/casks.sh @@ -3,6 +3,8 @@ #: List all locally installable casks including short names. #: +# Don't need shellcheck to follow the `source`. +# shellcheck disable=SC1090 source "$HOMEBREW_LIBRARY/Homebrew/items.sh" homebrew-casks() { diff --git a/Library/Homebrew/cmd/formulae.sh b/Library/Homebrew/cmd/formulae.sh index eee27c9629..a9deabfcfc 100644 --- a/Library/Homebrew/cmd/formulae.sh +++ b/Library/Homebrew/cmd/formulae.sh @@ -3,6 +3,8 @@ #: List all locally installable formulae including short names. #: +# Don't need shellcheck to follow the `source`. +# shellcheck disable=SC1090 source "$HOMEBREW_LIBRARY/Homebrew/items.sh" homebrew-formulae() { diff --git a/Library/Homebrew/items.sh b/Library/Homebrew/items.sh index 6edf44dfc6..5792a742dc 100644 --- a/Library/Homebrew/items.sh +++ b/Library/Homebrew/items.sh @@ -14,7 +14,7 @@ homebrew-items() { items="$( \ find "$HOMEBREW_REPOSITORY/Library/Taps" \ -type d \( \ - -name $find_filter -o \ + -name "$find_filter" -o \ -name cmd -o \ -name .github -o \ -name lib -o \ @@ -25,11 +25,11 @@ homebrew-items() { sed "$sed_extended_regex_flag" \ -e 's/\.rb//g' \ -e 's_.*/Taps/(.*)/(home|linux)brew-_\1/_' \ - -e $sed_filter \ + -e "$sed_filter" \ )" local shortnames shortnames="$(echo "$items" | cut -d "/" -f 3)" echo -e "$items\n$shortnames" | \ - grep -v $grep_filter | \ + grep -v "$grep_filter" | \ sort -uf }