Skip to content

Instantly share code, notes, and snippets.

@mul14
Last active June 4, 2022 18:55
Show Gist options
  • Save mul14/6e44e8aac91c5dfca3871a8246f6f251 to your computer and use it in GitHub Desktop.
Save mul14/6e44e8aac91c5dfca3871a8246f6f251 to your computer and use it in GitHub Desktop.
I very often create new folder to demonstrate or experiment. Run mkdir, cd, git init, etc; each time when I need is painful. So, I create this simple bash script.
#!/bin/bash
demo () {
project_name=""
if [ $# -eq 0 ]; then
project_name=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 6 | head -n 1)
else
if [[ ( $1 == "--help") || $1 == "-h" ]]; then
cat << EOF
Create new folder within demo folder
Usage:
demo Create new folder with random name
demo project_name Create new folder with "project_name" as name
demo [-h|--help] Show this help
EOF
return 0
else
project_name=$1
fi
fi
folder="$HOME/demo/$project_name"
mkdir -p $folder
cd $folder
echo "*~\n.DS_Store\nnode_modules\n" > .gitignore
git init --quiet
git add .
git commit --quiet -m 'First commit'
echo ""
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
echo "Experimental project \"$project_name\" has been created"
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
echo ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment