Skip to content

Instantly share code, notes, and snippets.

@MrSwed
Last active July 12, 2023 14:06
Show Gist options
  • Save MrSwed/4bb4e0a8c2a2f35827e6d9b410642582 to your computer and use it in GitHub Desktop.
Save MrSwed/4bb4e0a8c2a2f35827e6d9b410642582 to your computer and use it in GitHub Desktop.
Enable or Disable git hooks
#!/usr/bin/env bash
# Enable or disable git hooks
#find .git/hooks/ -type f ! -name "*.*"
gitHooks=.git/hooks/
echo "git Hooks $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"
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}"' _ {} \;
;;
"off" ) echo "$1 Selected"
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"' _ {} \;
;;
"" )
echo "Current status:"
find $gitHooks -type f ! -name "*.*"
find $gitHooks -type f -name "*.off"
;;
esac
@helhum
Copy link

helhum commented Feb 23, 2022

Thanks! This just helped me a lot. Was about to write sth. like this on my own, but then found this. 💖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment