#!/usr/bin/env bash
## Runs pylint on any .py files modified or added in the git status output.
## Source: git-extra-commands

#
# Author: Joe Block <jpb@unixorn.net>
#
# This script runs pylint on each of the modified python files in a git status
# command.
#
# This code is under the Apache license (see LICENSE in this repository)

NEW_FILES=$(git status | grep 'new file:' | grep -e '.py$' | awk '{print $3}')
MODIFIED_FILES=$(git status | grep 'modified:' | grep -e '.py$' | awk '{print $2}')

if [[ -z $MODIFIED_FILES ]] && [[ -z $NEW_FILES ]]; then
  echo "No modified or new files found"
fi

for file in $MODIFIED_FILES $NEW_FILES
do
  printf "Pylinting ... [\033[32;1m $file\033[0m ]\n\r"
  pylint "${file}"
  echo
done
