From 6dd195581ea0a986c0984f9356d0687b5b188d84 Mon Sep 17 00:00:00 2001 From: Charles Gould Date: Thu, 20 Feb 2020 02:20:01 -0500 Subject: [PATCH] fish: add homebrew functions --- fish/functions/brew_installed.fish | 15 +++++++++++++++ fish/functions/brew_remove.fish | 7 +++++++ fish/functions/brew_search.fish | 7 +++++++ 3 files changed, 29 insertions(+) create mode 100644 fish/functions/brew_installed.fish create mode 100644 fish/functions/brew_remove.fish create mode 100644 fish/functions/brew_search.fish diff --git a/fish/functions/brew_installed.fish b/fish/functions/brew_installed.fish new file mode 100644 index 0000000..c595a6a --- /dev/null +++ b/fish/functions/brew_installed.fish @@ -0,0 +1,15 @@ +function brew_installed --description "List installed top-level formulas" + set --local __brew_pkgs '' + set --local __brew_deps '' + + for __brew_pkg in (brew deps --installed) + set __brew_pkgs $__brew_pkgs (string split ':' $__brew_pkg | head -n 1) + set __brew_deps $__brew_deps (string split ' ' (string split ':' $__brew_pkg | tail -n +2)) + end + + for __brew_pkg in $__brew_pkgs + if not contains $__brew_pkg $__brew_deps + echo $__brew_pkg + end + end +end diff --git a/fish/functions/brew_remove.fish b/fish/functions/brew_remove.fish new file mode 100644 index 0000000..49d9d03 --- /dev/null +++ b/fish/functions/brew_remove.fish @@ -0,0 +1,7 @@ +function brew_remove --description "Select homebrew packages to remove" + set --local pkgs (brew leaves | eval "fzf $FZF_DEFAULT_OPTS --multi --header='[brew:uninstall]'") + + if not test (count $pkgs) = 0 + brew uninstall $pkgs + end +end diff --git a/fish/functions/brew_search.fish b/fish/functions/brew_search.fish new file mode 100644 index 0000000..d00b1c6 --- /dev/null +++ b/fish/functions/brew_search.fish @@ -0,0 +1,7 @@ +function brew_search --description "Find homebrew packages to install" + set --local pkgs (brew search | eval "fzf $FZF_DEFAULT_OPTS --multi --header='[brew:install]'") + + if not test (count $pkgs) = 0 + brew install $pkgs + end +end