#!/usr/bin/env bash RED='\033[0;31m' GR='\033[0;32m' NC='\033[0m' # No color today=$(date '+%Y-%m-%d') default_start="2020-01-01" config_file=".pickOptions.sh" export COLUMNS=80 IFS=$'\n' echo -e "`cat < /dev/null; then echo -e "${RED}$edate is not valid. Try again.${NC}" continue else declare -g ${date}=$edate break fi ;; esac done done } get_users () { echo -e "Select users\n" for auth in auth1 auth2 do if [[ $auth == "auth1" ]]; then repo=$br1 else repo=$br2 fi echo -e "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) echo "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 echo -e "${RED}" $(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 echo " ... saved" ;; *) echo " ... not saved" ;; esac } read_settings () { if [[ -f ${config_file} ]]; then echo -e "\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: "} echo -e "$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" echo " ... read" ;; *) echo " ... 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