<commit_before>#!/usr/bin/env bash

koopa::install_homebrew() { # {{{1
    # """
    # Install Homebrew.
    # @note Updated 2021-07-28.
    #
    # @seealso
    # - https://docs.brew.sh/Installation
    # - https://github.com/Homebrew/legacy-homebrew/issues/
    #       46779#issuecomment-162819088
    # - https://github.com/Linuxbrew/brew/issues/556
    #
    # macOS:
    # NOTE This function won't run on macOS clean install due to very old Bash.
    # Installs to '/usr/local' on Intel and '/opt/homebrew' on Apple Silicon.
    #
    # Linux:
    # Creates a new linuxbrew user and installs to /home/linuxbrew/.linuxbrew.
    # """
    local tee tmp_dir
    koopa::assert_has_no_args "$#"
    if koopa::is_installed 'brew'
    then
        koopa::alert_note 'Homebrew is already installed.'
        return 0
    fi
    koopa::assert_is_admin
    koopa::assert_is_installed 'yes'
    name_fancy='Homebrew'
    koopa::install_start "$name_fancy"
    koopa::is_macos && koopa::macos_install_xcode_clt
    tee="$(koopa::locate_tee)"
    tmp_dir="$(koopa::tmp_dir)"
    (
        koopa::cd "$tmp_dir"
        file='install.sh'
        url="https://raw.githubusercontent.com/Homebrew/install/master/${file}"
        koopa::download "$url"
        koopa::chmod +x "$file"
        yes | "./${file}" || true
    ) 2>&1 | "$tee" "$(koopa::tmp_log_file)"
    koopa::rm "$tmp_dir"
    koopa::install_success "$name_fancy"
    return 0
}

koopa::install_homebrew_bundle() { # {{{1
    # """
    # Install Homebrew packages using Bundle Brewfile.
    # @note Updated 2021-05-25.
    #
    # Custom brewfile is supported using a positional argument.
    # """
    local brewfile install_args name_fancy
    koopa::assert_has_args_le "$#" 1
    koopa::assert_is_admin
    brewfile="${1:-$(koopa::brew_brewfile)}"
    name_fancy='Homebrew Bundle'
    koopa::install_start "$name_fancy"
    koopa::assert_is_installed 'brew'
    koopa::assert_is_file "$brewfile"
    koopa::dl 'Brewfile' "$brewfile"
    brew analytics off
    install_args=(
        # > '--debug'
        # > '--verbose'
        "--file=${brewfile}"
        '--force'
        '--no-lock'
        '--no-upgrade'
    )
    # Note that cask specific args are handled by 'HOMEBREW_CASK_OPTS' global
    # variable, which is defined in our main Homebrew activation function.
    brew bundle install "${install_args[@]}"
    return 0
}

koopa::uninstall_homebrew() { # {{{1
    # """
    # Uninstall Homebrew.
    # @note Updated 2021-07-28.
    # @seealso
    # - https://docs.brew.sh/FAQ
    # """
    local file name_fancy tee tmp_dir url user
    if ! koopa::is_installed 'brew'
    then
        koopa::alert_is_not_installed 'Homebrew'
        return 0
    fi
    koopa::assert_is_admin
    koopa::assert_is_installed 'yes'
    name_fancy='Homebrew'
    user="$(koopa::user)"
    koopa::uninstall_start "$name_fancy"
    koopa::assert_has_no_args "$#"
    # Note that macOS Catalina now uses Zsh instead of Bash by default.
    if koopa::is_macos
    then
        koopa::alert 'Changing default shell to system Zsh.'
        chsh -s '/bin/zsh' "$user"
    fi
    tee="$(koopa::locate_tee)"
    tmp_dir="$(koopa::tmp_dir)"
    (
        koopa::cd "$tmp_dir"
        file='uninstall.sh'
        url="https://raw.githubusercontent.com/Homebrew/install/master/${file}"
        koopa::download "$url"
        koopa::chmod +x "$file"
        yes | "./${file}" || true
    ) 2>&1 | "$tee" "$(koopa::tmp_log_file)"
    koopa::rm "$tmp_dir"
    koopa::uninstall_success "$name_fancy"
    return 0
}

koopa::update_homebrew() { # {{{1
    # """
    # Updated outdated Homebrew brews and casks.
    # @note Updated 2021-05-25.
    #
    # @seealso
    # - Refer to useful discussion regarding '--greedy' flag.
    # - https://discourse.brew.sh/t/brew-cask-outdated-greedy/3391
    # - https://github.com/Homebrew/brew/issues/9139
    # - https://thecoatlessprofessor.com/programming/
    #       macos/updating-a-homebrew-formula/
    # """
    local name_fancy
    koopa::assert_has_no_args "$#"
    koopa::assert_is_installed 'brew'
    koopa::assert_is_admin
    name_fancy='Homebrew'
    koopa::update_start "$name_fancy"
    koopa::brew_reset_permissions
    koopa::brew_reset_core_repo
    brew analytics off
    brew update &>/dev/null
    koopa::is_macos && koopa::macos_brew_upgrade_casks
    koopa::brew_upgrade_brews
    koopa::brew_cleanup
    koopa::brew_reset_permissions
    koopa::update_success "$name_fancy"
    return 0
}
<commit_msg>Speed up Homebrew updater<commit_after>#!/usr/bin/env bash

koopa::install_homebrew() { # {{{1
    # """
    # Install Homebrew.
    # @note Updated 2021-07-28.
    #
    # @seealso
    # - https://docs.brew.sh/Installation
    # - https://github.com/Homebrew/legacy-homebrew/issues/
    #       46779#issuecomment-162819088
    # - https://github.com/Linuxbrew/brew/issues/556
    #
    # macOS:
    # NOTE This function won't run on macOS clean install due to very old Bash.
    # Installs to '/usr/local' on Intel and '/opt/homebrew' on Apple Silicon.
    #
    # Linux:
    # Creates a new linuxbrew user and installs to /home/linuxbrew/.linuxbrew.
    # """
    local tee tmp_dir
    koopa::assert_has_no_args "$#"
    if koopa::is_installed 'brew'
    then
        koopa::alert_note 'Homebrew is already installed.'
        return 0
    fi
    koopa::assert_is_admin
    koopa::assert_is_installed 'yes'
    name_fancy='Homebrew'
    koopa::install_start "$name_fancy"
    koopa::is_macos && koopa::macos_install_xcode_clt
    tee="$(koopa::locate_tee)"
    tmp_dir="$(koopa::tmp_dir)"
    (
        koopa::cd "$tmp_dir"
        file='install.sh'
        url="https://raw.githubusercontent.com/Homebrew/install/master/${file}"
        koopa::download "$url"
        koopa::chmod +x "$file"
        yes | "./${file}" || true
    ) 2>&1 | "$tee" "$(koopa::tmp_log_file)"
    koopa::rm "$tmp_dir"
    koopa::install_success "$name_fancy"
    return 0
}

koopa::install_homebrew_bundle() { # {{{1
    # """
    # Install Homebrew packages using Bundle Brewfile.
    # @note Updated 2021-05-25.
    #
    # Custom brewfile is supported using a positional argument.
    # """
    local brewfile install_args name_fancy
    koopa::assert_has_args_le "$#" 1
    koopa::assert_is_admin
    brewfile="${1:-$(koopa::brew_brewfile)}"
    name_fancy='Homebrew Bundle'
    koopa::install_start "$name_fancy"
    koopa::assert_is_installed 'brew'
    koopa::assert_is_file "$brewfile"
    koopa::dl 'Brewfile' "$brewfile"
    brew analytics off
    install_args=(
        # > '--debug'
        # > '--verbose'
        "--file=${brewfile}"
        '--force'
        '--no-lock'
        '--no-upgrade'
    )
    # Note that cask specific args are handled by 'HOMEBREW_CASK_OPTS' global
    # variable, which is defined in our main Homebrew activation function.
    brew bundle install "${install_args[@]}"
    return 0
}

koopa::uninstall_homebrew() { # {{{1
    # """
    # Uninstall Homebrew.
    # @note Updated 2021-07-28.
    # @seealso
    # - https://docs.brew.sh/FAQ
    # """
    local file name_fancy tee tmp_dir url user
    if ! koopa::is_installed 'brew'
    then
        koopa::alert_is_not_installed 'Homebrew'
        return 0
    fi
    koopa::assert_is_admin
    koopa::assert_is_installed 'yes'
    name_fancy='Homebrew'
    user="$(koopa::user)"
    koopa::uninstall_start "$name_fancy"
    koopa::assert_has_no_args "$#"
    # Note that macOS Catalina now uses Zsh instead of Bash by default.
    if koopa::is_macos
    then
        koopa::alert 'Changing default shell to system Zsh.'
        chsh -s '/bin/zsh' "$user"
    fi
    tee="$(koopa::locate_tee)"
    tmp_dir="$(koopa::tmp_dir)"
    (
        koopa::cd "$tmp_dir"
        file='uninstall.sh'
        url="https://raw.githubusercontent.com/Homebrew/install/master/${file}"
        koopa::download "$url"
        koopa::chmod +x "$file"
        yes | "./${file}" || true
    ) 2>&1 | "$tee" "$(koopa::tmp_log_file)"
    koopa::rm "$tmp_dir"
    koopa::uninstall_success "$name_fancy"
    return 0
}

koopa::update_homebrew() { # {{{1
    # """
    # Updated outdated Homebrew brews and casks.
    # @note Updated 2021-08-02.
    #
    # @seealso
    # - Refer to useful discussion regarding '--greedy' flag.
    # - https://discourse.brew.sh/t/brew-cask-outdated-greedy/3391
    # - https://github.com/Homebrew/brew/issues/9139
    # - https://thecoatlessprofessor.com/programming/
    #       macos/updating-a-homebrew-formula/
    # """
    local name_fancy reset
    koopa::assert_is_installed 'brew'
    koopa::assert_is_admin
    reset=0
    while (("$#"))
    do
        case "$1" in
            --no-reset)
                reset=0
                shift 1
                ;;
            --reset)
                reset=1
                shift 1
                ;;
            *)
                koopa::invalid_arg "$1"
                ;;
        esac
    done
    koopa::assert_has_no_args "$#"
    name_fancy='Homebrew'
    koopa::update_start "$name_fancy"
    if [[ "$reset" -eq 1 ]]
    then
        koopa::brew_reset_permissions
        koopa::brew_reset_core_repo
    fi
    brew analytics off
    brew update &>/dev/null
    if koopa::is_macos
    then
        koopa::macos_brew_upgrade_casks
    fi
    koopa::brew_upgrade_brews
    koopa::brew_cleanup
    if [[ "$reset" -eq 1 ]]
    then
        koopa::brew_reset_permissions
    fi
    koopa::update_success "$name_fancy"
    return 0
}

{'fraction_non_alphanumeric': 0.13812038014783526, 'fraction_numerical': 0.016367476240760296, 'mean_word_length': 2.5485200449606595, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5390715', 'n_tokens_mistral': 3528, 'n_tokens_neox': 3227, 'n_words': 641}