Skip to content

Instantly share code, notes, and snippets.

@robmiller
Last active December 13, 2018 16:37
Show Gist options
  • Save robmiller/5849541 to your computer and use it in GitHub Desktop.
Save robmiller/5849541 to your computer and use it in GitHub Desktop.
Quickly add Tim Pope's ctags generation scripts to all Git-controlled directories under the current one, so that you don't need to recreate your repositories.
# I love tpope's solution to ctags regeneration[1]; he creates
# a template from which all Git repositories take their default hooks,
# and then uses these hooks to regenerate ctags.
#
# [1]: http://tbaggery.com/2011/08/08/effortless-ctags-with-git.html
#
# It's an elegant solution, but what do you do about repositories that
# already exist? The template will only apply to newly cloned or newly
# initialised repositories.
#
# This one-liner should help; it will check for version-controlled
# directories one level below the current directory, and then copy the
# hooks over into them.
for x in *; do; [[ -d "$x/.git" ]] && echo $x && git init; done
# This won't actually generate the ctags; they'll be generated the next
# time one of the hooks is run (e.g. the next time you do a pull).
#
# If you'd like to regenerate them without waiting, you can use the
# following:
for x in *; do; [[ -e "$x/.git/hooks/ctags" ]] && echo $x && chdir $x && .git/hooks/ctags && cd ..; done
@robmiller
Copy link
Author

You could also do this with a find command, I suppose (untested):

find . -type d -name .git -exec cp -Rv ~/.git_template/ {} \;

@nelstrom
Copy link

You can also run git init on an existing git repository, which applies your global git templates anew. From the git init documentation

Running git init in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning git init is to pick up newly added templates.

@robmiller
Copy link
Author

Amazing! Much simpler.

@robmiller
Copy link
Author

Updated.

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