-
-
Save caspre24/123c41f0e26df1bfb5c8e5a4b4a68497 to your computer and use it in GitHub Desktop.
Enable or Disable git hooks
This file contains hidden or 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
#!/usr/bin/env bash | |
# Enable or disable git hooks | |
gitRoot=$(git root) | |
gitHooks=".git/hooks" | |
echo "git Hooks $gitRoot/$gitHooks" | |
option="${1}" | |
case ${option} in | |
"--help" | "-h" | "/?" | "-?" ) | |
echo "Usage: $0 <command> | |
<command> | |
on - Enable hooks | |
off - disable hooks | |
--help - This help | |
" | |
;; | |
"on" ) echo "$1 Selected" | |
pushd $gitRoot > /dev/null | |
find $gitHooks -type f -name "*.off" | grep "" >/dev/null || ( | |
echo Nothing to $1 | |
exit 0 | |
) | |
find $gitHooks -type f -name "*.off" -exec sh -c 'mv -v "$1" "${1%.off}"' _ {} \; | |
popd > /dev/null | |
;; | |
"off" ) echo "$1 Selected" | |
pushd $gitRoot > /dev/null | |
find $gitHooks -type f ! -name "*.*" | grep "" >/dev/null || ( | |
echo Nothing to $1 | |
exit 0 | |
) | |
find $gitHooks -type f ! -name "*.*" -exec sh -c 'mv -v "$1" "${1%}.off"' _ {} \; | |
popd > /dev/null | |
;; | |
"" ) | |
pushd $gitRoot > /dev/null | |
echo "Current status:" | |
find $gitHooks -type f ! -name "*.*" | |
find $gitHooks -type f -name "*.off" | |
popd > /dev/null | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment