Last active
June 22, 2020 01:26
-
-
Save aoki/7939324 to your computer and use it in GitHub Desktop.
Create `.gitkeep` files recursive.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if ! git rev-parse 2> /dev/null; then | |
echo -e "\033[0;31mERROR\033[0;39m: This directory is not git repository \033[0;31m:(\033[0;39m" | |
exit 1 | |
fi | |
Seek() { | |
for DIR in * ; do | |
if [ -d "${DIR}" ]; then | |
if [ -f "${DIR}/.gitkeep" ]; then | |
echo ".gitkeep already exists .gitkeep in `pwd`/${DIR}" | |
elif [ -z "$(ls -A ${DIR})" ]; then | |
touch ${DIR}/.gitkeep | |
echo "Create .gitkeep in `pwd`/${DIR}" | |
fi | |
(cd "${DIR}"; Seek;) | |
fi | |
done | |
} | |
Seek; | |
echo -e "done!! \033[0;32m:)\033[0;39m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works great if you're inside busybox and your
find
command doesn't support searching for empty directories.Otherwise if you have a modern
find
command use:find . -type d -empty -not -path "./.git/*" -exec touch {}/.gitkeep \;
Taken from: https://stackoverflow.com/a/31249949