Permalink
Browse files

Added install script for pre-commit hook and updated readme.md with i…

…nstallation instructions
  • Loading branch information...
1 parent 3dfdb73 commit 14e971b6aaf4d1e1164e854fee9c2c9522e8f735 @jaydee3 committed Feb 15, 2013
Showing with 77 additions and 7 deletions.
  1. +9 −3 .generateDescription.py
  2. +50 −0 .install-precommit-hook.sh
  3. +9 −0 .pre-commit.hook
  4. +9 −4 README.md
View
12 .generateDescription.py
@@ -5,12 +5,18 @@
print ">> Updating README.md based on .codesnippet files"
file = open('README.md', 'w')
-file.write('# CodeSnippets\n\nThese are my Xcode 4 CodeSnippets. Just clone them into the following path: \n')
-file.write('The folder must be empty, to clone the repository directly in it.\n\n')
+file.write('# CodeSnippets\n\n')
+file.write('These are my Xcode 4 CodeSnippets. \n')
+file.write('To use them, clone this repository into the following path:\n\n')
file.write(' cd ~/Library/Developer/Xcode/UserData/CodeSnippets\n')
file.write(' git clone git@github.com:jaydee3/CodeSnippets.git .\n\n')
+file.write('(The folder must be empty, to clone the repository directly in it.) \n')
file.write('And you\'re ready to go.\n\n')
-file.write('## Snippet Descriptions\n\n(generated with .generateDescription.py)\n\n')
+file.write('#### Installing the pre-commit hook \n')
+file.write('This README is generated automatically using `.generateDescription.py`. \n')
+file.write('To run this script automatically before each commit, install the pre-commit hook like this:\n\n')
+file.write(' sh .install-precommit-hook.sh\n\n')
+file.write('## Snippet Descriptions\n\n')
listing = os.listdir(".")
for fileName in listing:
View
50 .install-precommit-hook.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+#
+# Installs the pre-commit git hook
+# which will automatically update the README.md
+# and stage it for the current commit right before
+# every actual commit
+#
+
+hookfile=".pre-commit.hook"
+target=".git/hooks/pre-commit"
+backupTarget=".git/hooks/pre-commit.backup"
+
+# file existing options
+cancel=false
+overwrite=false
+backup=false
+
+# ask what to do with existing file
+if [ -e "$target" ] || [ -h "$target" ]; then
+ echo "A pre-commit hook already exists!"
+ echo "[c]ancel, [o]verwrite or [b]ackup"
+ while true; do
+ read answer
+ case $answer in
+ "c" ) cancel=true; break;;
+ "o" ) overwrite=true; break;;
+ "b" ) backup=true; break;;
+ * ) continue ;;
+ esac
+ done
+
+ if $overwrite; then
+ rm $target
+ fi
+
+ if $backup; then
+ mv $target $backupTarget
+ echo "Saved old hook as $backupTarget"
+ fi
+fi
+
+# cancel or install
+if $cancel; then
+ echo "Canceled"
+else
+ cp $hookfile $target
+ echo "Installed hook: $target"
+fi
+
+
View
9 .pre-commit.hook
@@ -0,0 +1,9 @@
+#!/bin/sh
+#
+# generate documentation, before commiting
+# this will update the readme.md
+#
+
+python .generateDescription.py
+git add README.md
+
View
13 README.md
@@ -1,16 +1,21 @@
# CodeSnippets
-These are my Xcode 4 CodeSnippets. Just clone them into the following path:
-The folder must be empty, to clone the repository directly in it.
+These are my Xcode 4 CodeSnippets.
+To use them, clone this repository into the following path:
cd ~/Library/Developer/Xcode/UserData/CodeSnippets
git clone git@github.com:jaydee3/CodeSnippets.git .
+(The folder must be empty, to clone the repository directly in it.)
And you're ready to go.
-## Snippet Descriptions
+#### Installing the pre-commit hook
+This README is generated automatically using `.generateDescription.py`.
+To run this script automatically before each commit, install the pre-commit hook like this:
+
+ sh .install-precommit-hook.sh
-(generated with .generateDescription.py)
+## Snippet Descriptions
**allocInit.codesnippet** (Initalize an object)
Shortcut: `alloc`

0 comments on commit 14e971b

Please sign in to comment.