Last active
November 16, 2016 15:51
-
-
Save ldante86/f4997e0569c04706a4606c41066ad48b to your computer and use it in GitHub Desktop.
Create new shell project
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 - | |
# SCRIPT: mkpr | |
# AUTHOR: Luciano D. Cecere | |
# YEAR: 2016 | |
# PURPOSE: This script creates a new shell project with common directories and files included. | |
# USAGE: mkpr project-name version | |
# NOTE: If a version number is not specified, 0.0.1 is used by default. | |
PROGRAM="${0##*/}" | |
PROJECT=$(echo "$1" | tr A-Z a-z | tr ' ' '_') | |
if [ "x$PROJECT" = "x" ]; then | |
echo "usage: $PROGRAM project-name version" | |
exit 1 | |
fi | |
VERSION="${2:-0.0.1}" | |
PROJECT="${PROJECT}-${VERSION}" | |
if [ -d "$PROJECT" ]; then | |
echo "$PROJECT already exists" | |
exit 1 | |
fi | |
EXE="${PROJECT}/bin/${PROJECT%-*}.sh" | |
mkdir -p "$PROJECT"/{bin,src,lib,scripts,test,man} && { | |
touch "${PROJECT}"/COPYING | |
touch "${PROJECT}"/README.md | |
echo "## README for ${PROJECT}" > "${PROJECT}"/README | |
touch "${PROJECT}"/TODO | |
echo "#!/bin/bash" >> "$EXE" | |
echo "# This file is a part of ${PROJECT%-*}" >> "$EXE" | |
chmod +x "$EXE" | |
cat /usr/share/common-licenses/GPL-2 > "${PROJECT}"/COPYING | |
} || { | |
echo "You do not have permission to create files on this system." | |
exit 1 | |
} | |
echo "${PWD}/${PROJECT}" created |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment