From fa9f56a5ed1b10ddb84d209e506fa50ab9a03a20 Mon Sep 17 00:00:00 2001 From: Sonny Date: Sun, 19 May 2019 14:18:51 +0000 Subject: [PATCH] Initial commit --- post-commit | 13 +++++++++++++ post-commit.d/ctags.sh | 20 ++++++++++++++++++++ pre-commit | 13 +++++++++++++ pre-commit.d/autoflake.sh | 14 ++++++++++++++ pre-commit.d/isort.sh | 14 ++++++++++++++ pre-commit.d/prettier.sh | 14 ++++++++++++++ pre-commit.d/yapf.sh | 14 ++++++++++++++ 7 files changed, 102 insertions(+) create mode 100755 post-commit create mode 100755 post-commit.d/ctags.sh create mode 100755 pre-commit create mode 100755 pre-commit.d/autoflake.sh create mode 100755 pre-commit.d/isort.sh create mode 100755 pre-commit.d/prettier.sh create mode 100755 pre-commit.d/yapf.sh diff --git a/post-commit b/post-commit new file mode 100755 index 0000000..d6bbe53 --- /dev/null +++ b/post-commit @@ -0,0 +1,13 @@ +#!/bin/bash + +# Check if the directory is the root directory +if [ ! -d ".git/" ]; then + echo "Please commit from within the root directory" + exit 1 +fi + +# Run every file inside the post-commit.d directory +for file in .git/hooks/post-commit.d/* +do + . $file +done diff --git a/post-commit.d/ctags.sh b/post-commit.d/ctags.sh new file mode 100755 index 0000000..4a3d0f8 --- /dev/null +++ b/post-commit.d/ctags.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +TAG_DIR="$HOME/.tags" +PROJECT_TAG_FILE="omx-gui.tags" + +if [ "$CREATE_TAGS" != true ]; then + exit 0 +fi + +if [ ! -x /usr/bin/ctags ]; then + echo "ctags binary is not executable or not present!" + exit 1 +fi + +if [ ! -d $HOME/.tags ]; then + echo "tags directory not created, creating it for you.." + /bin/mkdir $HOME/.tags +fi + +/usr/bin/ctags -f "$TAG_DIR/$PROJECT_TAG_FILE" -R --languages=Python,Javascript > /dev/null 2>&1 diff --git a/pre-commit b/pre-commit new file mode 100755 index 0000000..d1e29b9 --- /dev/null +++ b/pre-commit @@ -0,0 +1,13 @@ +#!/bin/bash + +# Check if the directory is the root directory +if [ ! -d ".git/" ]; then + echo "Please commit from within the root directory" + exit 1 +fi + +# Run every file inside the pre-commit.d directory +for file in .git/hooks/pre-commit.d/* +do + . $file +done diff --git a/pre-commit.d/autoflake.sh b/pre-commit.d/autoflake.sh new file mode 100755 index 0000000..7e4ec3f --- /dev/null +++ b/pre-commit.d/autoflake.sh @@ -0,0 +1,14 @@ +#!/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 diff --git a/pre-commit.d/isort.sh b/pre-commit.d/isort.sh new file mode 100755 index 0000000..09757c0 --- /dev/null +++ b/pre-commit.d/isort.sh @@ -0,0 +1,14 @@ +#!/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 ./env/bin/isort + + if [ $? -ne 0 ]; then + exit 1 + fi + + # Add back the modified/prettified files to staging + echo "$FILES" | xargs git add +fi diff --git a/pre-commit.d/prettier.sh b/pre-commit.d/prettier.sh new file mode 100755 index 0000000..86670c5 --- /dev/null +++ b/pre-commit.d/prettier.sh @@ -0,0 +1,14 @@ +#!/bin/sh +FILES=$(git diff --cached --name-only --diff-filter=ACM "*.js" | sed 's| |\\ |g') + +if [ ! -z "$FILES" ]; then + # Prettify all selected files + echo "$FILES" | xargs ./node_modules/.bin/prettier --write + + if [ $? -ne 0 ]; then + exit 1 + fi + + # Add back the modified/prettified files to staging + echo "$FILES" | xargs git add +fi diff --git a/pre-commit.d/yapf.sh b/pre-commit.d/yapf.sh new file mode 100755 index 0000000..df06a90 --- /dev/null +++ b/pre-commit.d/yapf.sh @@ -0,0 +1,14 @@ +#!/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 ./env/bin/yapf --in-place --verbose --style=./yapf.conf + + if [ $? -ne 0 ]; then + exit 1 + fi + + # Add back the modified files to staging + echo "$FILES" | xargs git add +fi