904f8685f75ff5dd3f544f8c6f2cabb8e5952e9a

Author
Ming Aldrich-Gan <mingaldrichgan@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(brew): improve `brews` list layout (#10135)

This is an improvement (in my opinion) to the `brews` command that prints each leaf formula (in white), followed by its dependencies (in blue), on each line. Compared to the existing flat list of formulae, the new layout is both more compact and more informative, by differentiating leaves from dependencies at a glance.

Screenshot:
<img width="530" src="https://user-images.githubusercontent.com/1753319/130641713-b78535c9-e3f5-4dbb-80f8-22bc00e1129d.png">

Diff

 1diff --git a/plugins/brew/brew.plugin.zsh b/plugins/brew/brew.plugin.zsh
 2index 532dd9be78a1af5a0c34c68781128873c7e7767a..070a083d0c69dc98465d0751af253a3cb2c3062c 100644
 3--- a/plugins/brew/brew.plugin.zsh
 4+++ b/plugins/brew/brew.plugin.zsh
 5@@ -1,5 +1,4 @@
 6 alias brewp='brew pin'
 7-alias brews='brew list -1'
 8 alias brewsp='brew list --pinned'
 9 alias bubo='brew update && brew outdated'
10 alias bubc='brew upgrade && brew cleanup'
11@@ -7,3 +6,16 @@ alias bubu='bubo && bubc'
12 alias buf='brew upgrade --formula'
13 alias bcubo='brew update && brew outdated --cask'
14 alias bcubc='brew upgrade --cask && brew cleanup'
15+
16+function brews() {
17+  local formulae="$(brew leaves | xargs brew deps --installed --for-each)"
18+  local casks="$(brew list --cask)"
19+
20+  local blue="$(tput setaf 4)"
21+  local bold="$(tput bold)"
22+  local off="$(tput sgr0)"
23+
24+  echo "${blue}==>${off} ${bold}Formulae${off}"
25+  echo "${formulae}" | sed "s/^\(.*\):\(.*\)$/\1${blue}\2${off}/"
26+  echo "\n${blue}==>${off} ${bold}Casks${off}\n${casks}"
27+}