core-unsorted.bash

#!/usr/bin/env bash

# These are functions that probably shouldn't be part of core....

function core_merge(){
    is_project_dir || return;

    ## @TODO determine version from branch history or something
    ## @TODO add "is_saved" feature... probably put it in `bent save` to skip when already done
    ## @TODO add "pull request" approach as an option
	
    current="$(cur_branch)"
    run show versions
    msg
    msg_instruct "Experimental Feature"
    msg "  We will save any changes before integrating..."

    prompt_quit "Enter version to use this feature on" version \
        && return;
    # @TODO check if branch exists before continuing

    prompt_quit "What does this new feature do? " featureDescript \
        && return;

    msg_status "Merging feature"
    run core save
    git checkout "${version}"
    git pull
    git merge --squash "${current}"

    msg_status "Saving changes"
    git commit -m "${featureDescript}"
    msg_status "Uploading"
    git push

    prompt_yes_or_quit "Declutter? Delete's feature branch" \
        && return;

    git branch -D "$current"
    git branch -d -r "origin/$current"
    git push origin ":$current"
}

function core_ignore(){
    is_project_dir || return
    type="$1"

    options=()
    while read -r line; do
        name="${line##*: \"}"
        name="${name%%\",*}"
        name="${name%%\.gitignore}"
        options+=("$name")
    done < <(curl https://api.github.com/repos/github/gitignore/git/trees/master | grep --ignore-case -e ".*$type.*\.gitignore")

    msg 
#  prompt_choose choice 
#      "# header" \
#      "'message" \
#      "choice_1" "shorthand" "choice 1 description" \
#      "choice_2" "shorthand 2" "choice 2 description" \
#  ;

    if [[ ${#options} -eq 0 ]]; then
        msg_notice "No gitignores found for '${type}'."
        msg_instruct "${cInstruct}[bent ignore]${cOff} to see a full list of options"
        msg_notice "Only 60 requests allowed per hour by github, so you may have exceeded this threshold."
        return
    fi

    prompt_args=("# Choose gitignore file")
    for opt in "${options[@]}"; do
        prompt_args+=("${opt}" "${opt,,}" "${opt}.gitignore")
    done


    
    prompt_args+=("'")
    prompt_args+=("'  File list from https://github.com/github/gitignore")
    prompt_args+=("' ${cInstruct}[bent ignore str]${cOff} to filter this list")
    prompt_choose file "${prompt_args[@]}" || return;

    file="${file}.gitignore"
    msg "Will download ${file}"
    dest="$(project_dir)/.gitignore"
    if [[ -f "$dest" ]]; then
        msg_notice "'$dest' will be overwritten!"
    fi
    prompt_yes_or_quit "Download ${file} ?" && return;

    url="https://raw.githubusercontent.com/github/gitignore/master/${file}"

    content="$(curl $url)"
    curl "$url" -o "$dest"
}