Skip to content

Instantly share code, notes, and snippets.

@caspre24
Forked from MrSwed/git-hooks.sh
Created June 25, 2021 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caspre24/123c41f0e26df1bfb5c8e5a4b4a68497 to your computer and use it in GitHub Desktop.
Save caspre24/123c41f0e26df1bfb5c8e5a4b4a68497 to your computer and use it in GitHub Desktop.
Enable or Disable git hooks
#!/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