Last active
April 12, 2016 14:41
-
-
Save jpmartha/986c9a3e432532df2faa3cb12076a09f to your computer and use it in GitHub Desktop.
Generate a new package's README.md from an existing package's README.md
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
#!/usr/bin/env bash | |
echo | |
usage() { | |
echo "OVERVIEW:" | |
echo " Generate a new package's README.md from an existing package's README.md" | |
echo | |
echo "USAGE:" | |
echo " generate-readme existing-package-path existing-package-name new-package-name" | |
echo | |
echo "EXAMPLE:" | |
echo " generate-readme ../Pokemon Pokemon DragonBall" | |
echo | |
echo " HOME Directory" | |
echo " ├── Pokemon" | |
echo " │ └── README.md" | |
echo " └── DragonBall (Current Directory)" | |
echo | |
} | |
replace_package_name() { | |
sed -i '' -e 's/'$EXISTING_PACKAGE_NAME'/'$NEW_PACKAGE_NAME'/g' $NEW_PACKAGE_README | |
} | |
if [ -z "$1" ]; then | |
usage | |
exit 1 | |
else | |
if [ -d $1 ]; then | |
export EXISTING_PACKAGE_PATH=$1 | |
export EXISTING_PACKAGE_README=$EXISTING_PACKAGE_PATH/README.md | |
if [ -a $EXISTING_PACKAGE_README ]; then | |
if [ -n "$2" ] && [ -n "$3" ]; then | |
export EXISTING_PACKAGE_NAME=$2 | |
export NEW_PACKAGE_NAME=$3 | |
else | |
echo "ERROR: Please enter 2 package names." | |
echo | |
exit 1 | |
fi | |
else | |
echo "ERROR: $EXISTING_PACKAGE_README doesn't exist." | |
echo | |
exit 1 | |
fi | |
else | |
echo "ERROR: $1 directory doesn't exist." | |
echo | |
exit 1 | |
fi | |
fi | |
export NEW_PACKAGE_README=~+/README.md | |
cp -f $EXISTING_PACKAGE_README $NEW_PACKAGE_README | |
replace_package_name | |
cat $NEW_PACKAGE_README | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
# An Existing Package's README.md
# A New Package's README.md