Skip to content

Instantly share code, notes, and snippets.

@Willshaw
Last active November 11, 2015 18:17
Show Gist options
  • Save Willshaw/615086649c254a3952bc to your computer and use it in GitHub Desktop.
Save Willshaw/615086649c254a3952bc to your computer and use it in GitHub Desktop.
Copy hook into multiple repos
ls -la | awk '{print $9}' | grep -v comcar | egrep '^[a-z]' | while read -r line; do sed -e "s/myrepo/$line/" myrepo/hooks/post-receive > $line/hooks/post-receive; done
#
# Break down of the above command is below - don't try to run the bits
# on their own, you need to pipe the outputs between, like the example above
#
# List contentsfiles in current directory - full list view, row per file/folder
ls -la
# Only print the 9th column (folder name)
awk '{print $9}'
# Ignore (-v) the "myepo" folder, that's the one we are copying from
grep -v myrepo
# Filter list to ignore hidden folders (e.g. the . and .. at the start of ls -a)
egrep '^[a-z]'
# loop over the lines
while read -r line;
# do text replacement of "myrepo" for the value of the current line.
# we're replacing the contents of myrepo/hooks/post-receive with
# the subsituted (sed) value and creating the $line/hooks/post-receive file...
do sed -e "s/myrepo/$line/" myrepo/hooks/post-receive > $line/hooks/post-receive;
# then we end the while loop
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment