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

CLR_SUCCESS="\033[1;32m"    # BRIGHT GREEN
CLR_CLEAR="\033[0m"         # DEFAULT COLOR

PULSEBRIDGE_PATH="$HOME/.pulsebridge"
PULSEBRIDGE_PROMPT="$HOME/.pulsebridge/prompt"

function success() {
    echo -e "${CLR_SUCCESS}$1${CLR_CLEAR}"
}

now=$(date +"%Y%m%d_%H%M%S")
backup_path="$PULSEBRIDGE_PATH/backup/prompt/$now"

success "Creating backup path : $backup_path..."
mkdir -p "$backup_path" 1>/dev/null

if [ -d $PULSEBRIDGE_PROMPT ]; then
    success "Backing up $PULSEBRIDGE_PROMPT..."
    cp -R $PULSEBRIDGE_PROMPT/* "$backup_path" 1>/dev/null

    success "Removing $PULSEBRIDGE_PROMPT..."
    rm -rf $PULSEBRIDGE_PROMPT 1>/dev/null
fi

success "Creating $PULSEBRIDGE_PROMPT..."
mkdir -p $PULSEBRIDGE_PROMPT/bin 1>/dev/null

success "Installing PulseBridge Prompt to $PULSEBRIDGE_PROMPT..."
cp -Rf src/* $PULSEBRIDGE_PROMPT 1>/dev/null

if [ -f $backup_path/scripts/bookmarks.sh ]; then
    success "Restoring bookmarks..."
    cp -R $backup_path/scripts/bookmarks.sh $PULSEBRIDGE_PROMPT/scripts 1>/dev/null
fi

if [ -f $backup_path/scripts/variables.sh ]; then
    success "Restoring variables..."
    cp -R $backup_path/scripts/variables.sh $PULSEBRIDGE_PROMPT/scripts 1>/dev/null
fi

for template in template/*; do
    name=$(basename "$template")
    path=$HOME/.${name}

    if [ -f $path ]; then
        success "Backing up ${name}..."
        cp $path $backup_path/$name
    fi

    cat $template > $path
done

LOCAL_PREFIX=/usr/local
BASH_COMPLETION=$LOCAL_PREFIX/etc/bash_completion.d
UNAME=$(uname)
UNAME_INSTALL="./uname/install-$UNAME.sh"

if [ -e /etc/os-release ]; then
    . /etc/os-release

    UNAME_INSTALL="./uname/install-$ID.sh"
fi

if [ -f $UNAME_INSTALL ]; then
    . $UNAME_INSTALL
fi

GIT_PROMPT_NAME=git-prompt.sh
GIT_COMPLETE_NAME=git-flow-completion.bash
GIT_PROMPT_URI=https://raw.githubusercontent.com/lyze/posh-git-sh/master/$GIT_PROMPT_NAME
GIT_COMPLETE_URI=https://raw.githubusercontent.com/petervanderdoes/git-flow-completion/develop/$GIT_COMPLETE_NAME
PROMPT_COMPLETION=$PULSEBRIDGE_PROMPT/completions

if [ -f "$BASH_COMPLETION/$GIT_COMPLETE_NAME" ]; then
    success "Removing git flow bash completion..."
    rm -rf "$BASH_COMPLETION/$GIT_COMPLETE_NAME" 1>/dev/null
fi

if [ -f "$BASH_COMPLETION/$GIT_PROMPT_NAME" ]; then
    success "Removing crappy git-prompt..."
    rm -rf "$BASH_COMPLETION/$GIT_PROMPT_NAME" 1>/dev/null
fi

if [ ! -d "$PROMPT_COMPLETION" ]; then
    mkdir -p "$PROMPT_COMPLETION" 1>/dev/null
fi

success "Downloading better git-prompt..."
result=$(curl -sLD- "$GIT_PROMPT_URI" -o "$PROMPT_COMPLETION/$GIT_PROMPT_NAME" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")

if [ "$result" = "200" ]; then
    success "Successfully installed git-prompt..."
    chmod +x "PROMPT_COMPLETION/$GIT_PROMPT_NAME" 1>/dev/null 2>&1
fi

success "Downloading git-flow completion..."
result=$(curl -sLD- "$GIT_COMPLETE_URI" -o "$PROMPT_COMPLETION/$GIT_COMPLETE_NAME" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")

if [ "$result" = "200" ]; then
    success "Successfully installed git-flow completion..."
    chmod +x "$PROMPT_COMPLETION/$GIT_COMPLETE_NAME" 1>/dev/null 2>&1
fi

CURL_OPT='-s'
if [ ! -z "${GH_TOKEN:-}" ]; then
    CURL_OPT='$CURL_OPT -H "Authorization: token $GH_TOKEN"'
fi

SHA_URI="https://api.github.com/repos/pulsebridge/prompt/commits/master"
PROMPT_SHA=$(curl $CURL_OPT $SHA_URI | grep sha | head -n 1 | sed 's#.*\:.*"\(.*\).*",#\1#')
PROMPT_SHA_PATH=$HOME/.pulsebridge/prompt/$PROMPT_SHA

touch $PROMPT_SHA_PATH

echo -e "${CLR_SUCCESS}"
echo "#######################################"
echo "#######################################"
echo "   PLEASE OPEN A NEW TERMINAL WINDOW"
echo "#######################################"
echo "#######################################"
echo -e "${CLR_CLEAR}"

. ~/.bash_profile<commit_msg>chore(install): source of bash_profile does not work on all platforms; reverting<commit_after>#!/usr/bin/env bash

CLR_SUCCESS="\033[1;32m"    # BRIGHT GREEN
CLR_CLEAR="\033[0m"         # DEFAULT COLOR

PULSEBRIDGE_PATH="$HOME/.pulsebridge"
PULSEBRIDGE_PROMPT="$HOME/.pulsebridge/prompt"

function success() {
    echo -e "${CLR_SUCCESS}$1${CLR_CLEAR}"
}

now=$(date +"%Y%m%d_%H%M%S")
backup_path="$PULSEBRIDGE_PATH/backup/prompt/$now"

success "Creating backup path : $backup_path..."
mkdir -p "$backup_path" 1>/dev/null

if [ -d $PULSEBRIDGE_PROMPT ]; then
    success "Backing up $PULSEBRIDGE_PROMPT..."
    cp -R $PULSEBRIDGE_PROMPT/* "$backup_path" 1>/dev/null

    success "Removing $PULSEBRIDGE_PROMPT..."
    rm -rf $PULSEBRIDGE_PROMPT 1>/dev/null
fi

success "Creating $PULSEBRIDGE_PROMPT..."
mkdir -p $PULSEBRIDGE_PROMPT/bin 1>/dev/null

success "Installing PulseBridge Prompt to $PULSEBRIDGE_PROMPT..."
cp -Rf src/* $PULSEBRIDGE_PROMPT 1>/dev/null

if [ -f $backup_path/scripts/bookmarks.sh ]; then
    success "Restoring bookmarks..."
    cp -R $backup_path/scripts/bookmarks.sh $PULSEBRIDGE_PROMPT/scripts 1>/dev/null
fi

if [ -f $backup_path/scripts/variables.sh ]; then
    success "Restoring variables..."
    cp -R $backup_path/scripts/variables.sh $PULSEBRIDGE_PROMPT/scripts 1>/dev/null
fi

for template in template/*; do
    name=$(basename "$template")
    path=$HOME/.${name}

    if [ -f $path ]; then
        success "Backing up ${name}..."
        cp $path $backup_path/$name
    fi

    cat $template > $path
done

LOCAL_PREFIX=/usr/local
BASH_COMPLETION=$LOCAL_PREFIX/etc/bash_completion.d
UNAME=$(uname)
UNAME_INSTALL="./uname/install-$UNAME.sh"

if [ -e /etc/os-release ]; then
    . /etc/os-release

    UNAME_INSTALL="./uname/install-$ID.sh"
fi

if [ -f $UNAME_INSTALL ]; then
    . $UNAME_INSTALL
fi

GIT_PROMPT_NAME=git-prompt.sh
GIT_COMPLETE_NAME=git-flow-completion.bash
GIT_PROMPT_URI=https://raw.githubusercontent.com/lyze/posh-git-sh/master/$GIT_PROMPT_NAME
GIT_COMPLETE_URI=https://raw.githubusercontent.com/petervanderdoes/git-flow-completion/develop/$GIT_COMPLETE_NAME
PROMPT_COMPLETION=$PULSEBRIDGE_PROMPT/completions

if [ -f "$BASH_COMPLETION/$GIT_COMPLETE_NAME" ]; then
    success "Removing git flow bash completion..."
    rm -rf "$BASH_COMPLETION/$GIT_COMPLETE_NAME" 1>/dev/null
fi

if [ -f "$BASH_COMPLETION/$GIT_PROMPT_NAME" ]; then
    success "Removing crappy git-prompt..."
    rm -rf "$BASH_COMPLETION/$GIT_PROMPT_NAME" 1>/dev/null
fi

if [ ! -d "$PROMPT_COMPLETION" ]; then
    mkdir -p "$PROMPT_COMPLETION" 1>/dev/null
fi

success "Downloading better git-prompt..."
result=$(curl -sLD- "$GIT_PROMPT_URI" -o "$PROMPT_COMPLETION/$GIT_PROMPT_NAME" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")

if [ "$result" = "200" ]; then
    success "Successfully installed git-prompt..."
    chmod +x "PROMPT_COMPLETION/$GIT_PROMPT_NAME" 1>/dev/null 2>&1
fi

success "Downloading git-flow completion..."
result=$(curl -sLD- "$GIT_COMPLETE_URI" -o "$PROMPT_COMPLETION/$GIT_COMPLETE_NAME" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")

if [ "$result" = "200" ]; then
    success "Successfully installed git-flow completion..."
    chmod +x "$PROMPT_COMPLETION/$GIT_COMPLETE_NAME" 1>/dev/null 2>&1
fi

CURL_OPT='-s'
if [ ! -z "${GH_TOKEN:-}" ]; then
    CURL_OPT='$CURL_OPT -H "Authorization: token $GH_TOKEN"'
fi

SHA_URI="https://api.github.com/repos/pulsebridge/prompt/commits/master"
PROMPT_SHA=$(curl $CURL_OPT $SHA_URI | grep sha | head -n 1 | sed 's#.*\:.*"\(.*\).*",#\1#')
PROMPT_SHA_PATH=$HOME/.pulsebridge/prompt/$PROMPT_SHA

touch $PROMPT_SHA_PATH

echo -e "${CLR_SUCCESS}"
echo "#######################################"
echo "#######################################"
echo "   PLEASE OPEN A NEW TERMINAL WINDOW"
echo "#######################################"
echo "#######################################"
echo -e "${CLR_CLEAR}"
{'fraction_non_alphanumeric': 0.20005122950819673, 'fraction_numerical': 0.013063524590163935, 'mean_word_length': 4.2025316455696204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 6, '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': '282143', 'n_tokens_mistral': 3189, 'n_tokens_neox': 3006, 'n_words': 570}