diff --git a/cl b/cl index d866b62..29f306e 100755 --- a/cl +++ b/cl @@ -122,15 +122,29 @@ function schedule() { echo "$@" >> "$CLDIR/scheduled" } + +function prev_working_day() { + if [ "$(date +%a)" == 'Mon' ]; then modY=3;fi + date +%F -d "-${modY:-1} day" +} + +function today() { + date +%F + +} +function next_working_day() { + + if [ "$(date +%a)" == 'Fri' ]; then modT=3;fi + date +%F -d "+${modT:-1} day" +} + function captains_log() { # Take into account only the work week. # Might make sense in the future to check if there are any notes for the intervening days Sat/Sun # and display them if so - if [ "$(date +%a)" == 'Mon' ]; then modY=3;fi - if [ "$(date +%a)" == 'Fri' ]; then modT=3;fi - YESTERDAY=$(date +%F -d "-${modY:-1} day") - TODAY=$(date +%F) - TOMORROW=$(date +%F -d "+${modT:-1} day") + YESTERDAY=$(prev_working_day) + TODAY=$(today) + TOMORROW=$(next_working_day) if [ ${GIT:-1} ] && (git -C $CLDIR rev-parse 2>/dev/null) ; then GIT=1 @@ -151,6 +165,9 @@ function captains_log() { if [ ${1-x} == 'x' ]; then for i in YESTERDAY TODAY TOMORROW; do generate_file ${!i} + if [ $i == 'TODAY' ]; then + transfer_items $CLDIR/$YESTERDAY $CLDIR/$TODAY + fi done if [ -f "$CLDIR/backlog" ]; then vi $CLDIR/{$YESTERDAY,$TODAY,$TOMORROW,backlog} -s <( echo -e ":vsplit\n:wincmd w\n:next\n:vsplit\n:wincmd w\n:next\n:split\n:wincmd w\n:next") @@ -159,11 +176,11 @@ function captains_log() { fi else generate_file $1 + transfer_items $CLDIR/$YESTERDAY $CLDIR/$TODAY vi $CLDIR/$(date -d "$1" "+%F") fi - asset generate_links if [ $GIT -ne 0 ]; then @@ -232,10 +249,6 @@ function generate_file() { fi } - - - - function asset_generate_links() { # Either do files modified in the last 7 days, or all files if [ "$1" == "all" ]; then @@ -308,6 +321,34 @@ function asset() { } + + + +function transfer_items() { + + TRANSFER='' + + + while read line1; + do while read line2; do + MATCH=0 ; + VAL=$(echo "$(fstrcmp -- "$line1" "$line2") * 100"|bc -l|cut -d . -f1 ); + if [ $VAL -gt 60 ]; then + MATCH=1 + break + fi; + done < <(grep '^\s*[~-]' $2); + if [ $MATCH -eq 0 ]; then + TRANSFER="${TRANSFER}\n$line1" + fi + done < <(grep '^\s*[~-]' $1) + + + + if [ "$TRANSFER" != '' ]; then + echo -e "\nThese incomeplete/ongoing items have been transferred from $(basename "$1"):\n $TRANSFER" >> $2 + fi +} @@ -335,6 +376,7 @@ while [ $1 ]; do asset) shift; asset "$@"; exit;; *ASSET*) asset "$@"; exit;; help|--help|-h) help; exit;; + transfer) transfer_items $CLDIR/$(today) $CLDIR/$(next_working_day); exit;; *) break;; esac done