<commit_before>#!/bin/bash

cd "$(dirname "${BASH_SOURCE}")" && source "../utils.sh"

# Homebrew Formulae
# https://github.com/Homebrew/homebrew

declare -r -a HOMEBREW_FORMULAE=(
    "caskroom/cask/brew-cask"
    "coreutils"
    "curl --with-openssl"
    "wget --enable-iri"
    "git --without-completions"
    "mariadb"
    "htop-osx"
    "vim --override-system-vi"
    "node"
)

# Homebrew Php Formulae
# https://github.com/Homebrew/homebrew-php

declare -r -a HOMEBREW_PHP_FORMULAE=(
    "php56"
    "php56-xdebug"
    "php56-memcached"
    "composer"
    "drush"
    "drupal-code-sniffer"
)

# Homebrew Casks
# https://github.com/caskroom/homebrew-cask

declare -r -a HOMEBREW_CASKS=(
    # browsers
    "google-chrome"
    "firefox"
    "opera"

    # daily
    "alfred"

    # development
    "iterm2"
    "imagealpha"
    "imageoptim"
    "filezilla"
    "virtualbox"
    "java"
    "phpstorm"

    # optional editors
    # "atom"
    # "brackets"
    # "visual-studio-code"

    # communication
    "skype"
    "slack"

    # others
    "spotify"
    "qbittorrent"
    "vlc"
)

# Homebrew Alternate Casks
# https://github.com/caskroom/homebrew-versions

declare -r -a HOMEBREW_ALTERNATE_CASKS=(
)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

brew_install() {

    declare -r -a FORMULAE=("${!1}"); shift;
    declare -r CMD="$1"

    local i="", tmp=""

    for i in ${!FORMULAE[*]}; do
        tmp="${FORMULAE[$i]}"
        [ $(brew "$CMD" list "$tmp" &> /dev/null; printf $?) -eq 0 ] \
            && print_success "$tmp" \
            || execute "brew $CMD install $tmp" "$tmp"
    done

}

brew_tap() {

    declare -r REPOSITORY="$1"

    brew tap "$REPOSITORY" &> /dev/null

    [ "$(brew tap | grep "$REPOSITORY" &> /dev/null; printf $?)" -eq 0 ] \
        && (print_success "brew tap ($REPOSITORY)"; return 0) \
        || (print_error "brew tap ($REPOSITORY)"; return 1)

}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

main() {

    if ! xcode-select --print-path &> /dev/null; then

        # Prompt user to install the XCode Command Line Tools
        xcode-select --install &> /dev/null

        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        # Wait until the XCode Command Line Tools are installed
        until xcode-select --print-path &> /dev/null; do
            sleep 5
        done

        print_result $? 'Install XCode Command Line Tools'

        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        # Point the `xcode-select` developer directory to
        # the appropriate directory from within `Xcode.app`
        # https://github.com/alrra/dotfiles/issues/13

        sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
        print_result $? 'Make "xcode-select" developer directory point to Xcode'

        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        # Prompt user to agree to the terms of the Xcode license
        # https://github.com/alrra/dotfiles/issues/10

        sudo xcodebuild -license
        print_result $? 'Agree with the XCode Command Line Tools licence'

    fi

    print_result $? 'XCode Command Line Tools'

    # Homebrew
    if [ $(cmd_exists "brew") -eq 1 ]; then
        printf "\n" | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
        #  └─ simulate the ENTER keypress
        print_result $? "brew"
    fi

    if [ $(cmd_exists "brew") -eq 0 ]; then

        execute "brew update" "brew (update)"
        execute "brew upgrade --all" "brew (upgrade)"
        execute "brew cleanup" "brew (cleanup)"
        printf "\n"<commit_msg>fix unary operator error on osx<commit_after>#!/bin/bash

cd "$(dirname "${BASH_SOURCE}")" && source "../utils.sh"

# Homebrew Formulae
# https://github.com/Homebrew/homebrew

declare -r -a HOMEBREW_FORMULAE=(
    "caskroom/cask/brew-cask"
    "coreutils"
    "curl --with-openssl"
    "wget --enable-iri"
    "git --without-completions"
    "mariadb"
    "htop-osx"
    "vim --override-system-vi"
    "node"
)

# Homebrew Php Formulae
# https://github.com/Homebrew/homebrew-php

declare -r -a HOMEBREW_PHP_FORMULAE=(
    "php56"
    "php56-xdebug"
    "php56-memcached"
    "composer"
    "drush"
    "drupal-code-sniffer"
)

# Homebrew Casks
# https://github.com/caskroom/homebrew-cask

declare -r -a HOMEBREW_CASKS=(
    # browsers
    "google-chrome"
    "firefox"
    "opera"

    # daily
    "alfred"

    # development
    "iterm2"
    "imagealpha"
    "imageoptim"
    "filezilla"
    "virtualbox"
    "java"
    "phpstorm"

    # optional editors
    # "atom"
    # "brackets"
    # "visual-studio-code"

    # communication
    "skype"
    "slack"

    # others
    "spotify"
    "qbittorrent"
    "vlc"
)

# Homebrew Alternate Casks
# https://github.com/caskroom/homebrew-versions

declare -r -a HOMEBREW_ALTERNATE_CASKS=(
)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

brew_install() {

    declare -r -a FORMULAE=("${!1}"); shift;
    declare -r CMD="$1"

    local i="", tmp=""

    for i in ${!FORMULAE[*]}; do
        tmp="${FORMULAE[$i]}"
        [ $(brew "$CMD" list "$tmp" &> /dev/null; printf $?) -eq 0 ] \
            && print_success "$tmp" \
            || execute "brew $CMD install $tmp" "$tmp"
    done

}

brew_tap() {

    declare -r REPOSITORY="$1"

    brew tap "$REPOSITORY" &> /dev/null

    [ "$(brew tap | grep "$REPOSITORY" &> /dev/null; printf $?)" -eq 0 ] \
        && (print_success "brew tap ($REPOSITORY)"; return 0) \
        || (print_error "brew tap ($REPOSITORY)"; return 1)

}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

main() {

    if ! xcode-select --print-path &> /dev/null; then

        # Prompt user to install the XCode Command Line Tools
        xcode-select --install &> /dev/null

        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        # Wait until the XCode Command Line Tools are installed
        until xcode-select --print-path &> /dev/null; do
            sleep 5
        done

        print_result $? 'Install XCode Command Line Tools'

        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        # Point the `xcode-select` developer directory to
        # the appropriate directory from within `Xcode.app`
        # https://github.com/alrra/dotfiles/issues/13

        sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
        print_result $? 'Make "xcode-select" developer directory point to Xcode'

        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        # Prompt user to agree to the terms of the Xcode license
        # https://github.com/alrra/dotfiles/issues/10

        sudo xcodebuild -license
        print_result $? 'Agree with the XCode Command Line Tools licence'

    fi

    print_result $? 'XCode Command Line Tools'

    # Homebrew
    if ! cmd_exists "brew"; then
        printf "\n" | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
        #  └─ simulate the ENTER keypress
        print_result $? "brew"
    fi

    if cmd_exists "brew"; then

        execute "brew update" "brew (update)"
        execute "brew upgrade --all" "brew (upgrade)"
        execute "brew cleanup" "brew (cleanup)"
        printf "\n"
{'fraction_non_alphanumeric': 0.17222222222222222, 'fraction_numerical': 0.005420054200542005, 'mean_word_length': 1.7347165616895146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 42, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7565732', 'n_tokens_mistral': 2769, 'n_tokens_neox': 2614, 'n_words': 572}