Created
September 4, 2019 13:28
-
-
Save swiercz/4e3ca5a42ec0e3bad74e146654391ef1 to your computer and use it in GitHub Desktop.
Show PyCharm's diff tool with what's black is about to change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if black and charm is available | |
if ! which black > /dev/null; then | |
echo "black is not installed" | |
exit 1 | |
elif ! which charm > /dev/null; then | |
echo "charm command is not available" | |
exit 1 | |
fi | |
arg=$1 | |
# Exit if no argument given | |
if [ -z "$arg" ]; then | |
exit 1 | |
fi | |
# Get arg file extension | |
extension="${arg##*.}" | |
# Prepare tmp files | |
filetmp="$(mktemp -u).$extension" | |
difftmp=$(mktemp -u) | |
# copy contents of given file to tmp | |
cat "$arg" > $filetmp | |
# generate diff and save to tmp | |
black -l 120 --fast --diff "$arg" > $difftmp | |
# patch copied file with diff from black | |
patch $filetmp < $difftmp | |
# start py-charm diff | |
charm diff "$arg" $filetmp | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment