#!/bin/bash FILES=$(git diff --cached --name-only --diff-filter=ACM "*.py" | sed 's| |\\ |g') if [ ! -z "$FILES" ]; then # Format all selected files echo "$FILES" | xargs -I {} /bin/bash -c "/home/sonny/.local/bin/autoflake --in-place --remove-unused-variables {}" if [ $? -ne 0 ]; then exit 1 fi # Add back the modified files to staging echo "$FILES" | xargs git add fi