summary refs log tree commit diff
path: root/dot_local/share/zsh/brew/brew.plugin.zsh
blob: 8d9113a0690f89046dd643326858c09747b76787 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Set up brew
if [[ -v HOMEBREW_PREFIX ]] && [[ -f "${HOMEBREW_PREFIX}/bin/brew" ]]; then
    export HOMEBREW_NO_ENV_HINTS=1
    export HOMEBREW_NO_ANALYTICS=1
    eval "$(${HOMEBREW_PREFIX}/bin/brew shellenv)"
    fpath=("${HOMEBREW_PREFIX}/share/zsh/site-functions" $fpath)

    # Prefer GNU versions of certain tools
    local tool_bin
    for tool_bin in "${HOMEBREW_PREFIX}"/opt/*/libexec/gnubin(N); do
        if [[ "${tool_bin}" == */gsed/* ]]; then
            continue  # Alias to gnu-sed
        fi
        export PATH="${tool_bin}${PATH+:$PATH}"
        export MANPATH="$(dirname ${tool_bin})/gnuman${MANPATH+:$MANPATH}"
    done

    # Brew leaves and deps
    brews() {
        local formulae="$(brew leaves | xargs brew deps --installed --for-each)"
        local casks="$(brew list --cask)"
        local blue="$(tput setaf 4)"
        local bold="$(tput bold)"
        local off="$(tput sgr0)"
        echo "${blue}==>${off} ${bold}Formulae${off}"
        echo "${formulae}" | sed "s/^\(.*\):\(.*\)$/\1${blue}\2${off}/"
        echo "\n${blue}==>${off} ${bold}Casks${off}\n${casks}"
    }
fi