#!/usr/bin/env bash . $(pwd)/_utils.sh if [[ -z ${utils_loaded+x} ]]; then echo "Could not load utilities"; exit 1; fi today=$(date '+%Y-%m-%d') default_start=$(date --date='-9 month' '+%Y-%m-%d') config_file=".pickOptions.sh" export COLUMNS=80 IFS=$'\n' echo -e "`cat < /dev/null; then warn "$edate is not valid. Try again." continue else declare -g ${date}=$edate break fi ;; esac done done } get_users () { message "Select users\n" for auth in auth1 auth2 do if [[ $auth == "auth1" ]]; then repo=$br1 else repo=$br2 fi message "Optionally, select a ${GR}$repo${NC} author to filter by:\n" select os in $(git log --pretty=format:%an --after="$begin" --before="$end" $repo | sort | uniq; echo "None") do case $os in None) warn "No author selected, will show all authors." declare -g ${auth}="" break ;; *) declare -g ${auth}="$os" break ;; esac done # if [[ ${auth}=="" ]]; then break; fi done } get_pick () { read -e -p 'Optional string to filter on in (pick list): ' str } confirm_options () { read -n 1 -s -r -p "Press any key to continue or CTL-C to quit" echo -e "\n\n" } compare_branches () { for pick in $({ git log --pretty=format:%s%n --after="$begin" --before="$end" --author="$auth1" $br1 & git log --pretty=format:%s%n --after="$begin" --before="$end" --author="$auth2" $br2; } | grep "(.*$str.*)$" | sort | uniq -u); do confirmation $(git log --grep=$pick --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:"%cd, %s [ %h ]" --after=$begin --before=$end --author=$auth1 --author=$auth2 $br1 $br2) "${NC}" done } save_settings () { echo -e "`cat < $config_file confirmation " ... saved" ;; *) warn " ... not saved" ;; esac } read_settings () { if [[ -f ${config_file} ]]; then message "\nFound saved options:\n" values=$(<$config_file) values=${values/br1=/"First Branch: "} values=${values/br2=/"Second Branch: "} values=${values/auth1=/"First Author: "} values=${values/auth2=/"Second Author: "} values=${values/begin=/"Start Date: "} values=${values/end=/"End Date: "} values=${values/str=/"Pick Search String: "} message "$values\n" read -p 'Reuse these options now? [y/n]: ' -n1 read_opts; case $read_opts in Y|y) CONTEXT_DIR="${BASH_SOURCE%/*}" if [[ ! -d "$CONTEXT_DIR" ]]; then CONTEXT_DIR="$PWD"; fi . "$CONTEXT_DIR/$config_file" confirmation " ... read" ;; *) warn " ... not read" ;; esac fi } read_settings if [ -z ${br1+x} ] || [ -z ${br2+x} ]; then get_branches; fi if [ -z ${begin+x} ] || [ -z ${end+x} ]; then get_dates; fi if [[ ! $read_opts == [yY] ]]; then get_users get_pick save_settings fi confirm_options compare_branches