Skip to content

Instantly share code, notes, and snippets.

@jswright61
Last active May 14, 2019 15:00
Show Gist options
  • Save jswright61/1b9790f8306f775d412fa6d372da3391 to your computer and use it in GitHub Desktop.
Save jswright61/1b9790f8306f775d412fa6d372da3391 to your computer and use it in GitHub Desktop.
Bash / Zsh function to create .keep files

Quick little function to add a directory to a project

  1. Assumes it is run from the project root
  2. Creates the directory and all intermediate directories that don't yet exist
  3. Places an empty file, .keep, in the new directory
  4. Adds the directory to .gitignore and excludes the .keep file in the .gitignore
  5. The file type just gets syntax highlighting right - copy the function and add it to you .zshrc or .bash_profile or whatever

This could be easily adapted to be an executable placed in your path

function keep() {
if [ $# -eq 0 ]; then
echo "Please provide a directory name"
else
mkdir -p "$1"
touch "$1/.keep"
echo "$1/*" >> .gitignore
echo "!$1/.keep" >> .gitignore
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment