github.com/StackExchange/blackbox/v2@v2.0.1-0.20220331193400-d84e904973ab/binv2/blackbox_whatsnew (about) 1 #!/usr/bin/env bash 2 3 # 4 # blackbox_whatsnew - show what has changed in the last commit for a given file 5 # 6 exec blackbox whatsnew "$@" 7 exit 0 8 9 set -e 10 source "${0%/*}/_blackbox_common.sh" 11 12 if [[ $# -ne 1 ]] 13 then 14 echo "Pass only 1 file at a time" 15 exit 1 16 fi 17 18 fail_if_not_in_repo 19 gpg_agent_notice 20 21 COLUMNS=`tput cols` 22 FILE=$1 23 GIT="git log --abbrev-commit --pretty=oneline" 24 CURR_COMMIT=`$GIT $FILE | head -1 | awk '{print $1}'` 25 PREV_COMMIT=`$GIT ${CURR_COMMIT}~1 $FILE | head -1 | awk '{print $1}'` 26 # Use colordiff if available 27 if which colordiff > /dev/null 2>&1 28 then DIFF="colordiff" 29 else DIFF="diff" 30 fi 31 32 cat_commit() 33 { 34 COMMIT=$1 35 git checkout $COMMIT $FILE 36 echo "[$COMMIT] $FILE" 37 echo "---------------------" 38 "${BLACKBOX_HOME}/blackbox_cat" $FILE | sed '/========== PLAINFILE/,/========== EXTRACTING/d' 39 } 40 41 CURR_CONTENT=`cat_commit $CURR_COMMIT` 42 PREV_CONTENT=`cat_commit $PREV_COMMIT` 43 clear 44 45 # For some unknown reason this command executes fine but return exit code 1 46 $DIFF -y --width $COLUMNS \ 47 <(echo "CURRENT" "$CURR_CONTENT" | fold -w $(( $COLUMNS / 2 - 4 )) ) \ 48 <(echo "PREVIOUS" "$PREV_CONTENT" | fold -w $(( $COLUMNS / 2 - 4 )) ) 49 50 git checkout $CURR_COMMIT $FILE 51 echo