Skip to content

Instantly share code, notes, and snippets.

@vergenzt
Created April 15, 2022 20:38
Show Gist options
  • Save vergenzt/c47c8ecb47fab6d34030905bb6c9ffb6 to your computer and use it in GitHub Desktop.
Save vergenzt/c47c8ecb47fab6d34030905bb6c9ffb6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euf -o pipefail # https://sipb.mit.edu/doc/safe-shell/
# https://medium.com/@LihauTan/2f87c770ea9c
find . -name .gitignore \
-exec awk '
FNR==1 { print "\n## " FILENAME } \
FNR==1 { cmd = "dirname " FILENAME; cmd | getline DIRNAME; close(cmd) } \
/^ *#/ { print $0; next } \
/^[^!]/ { print DIRNAME "/" $0 } \
/^!/ { print "!" DIRNAME "/" substr($0,2) } \
' '{}' '+' \
> .dockerignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment