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