Skip to content

Instantly share code, notes, and snippets.

@jpmartha
Last active April 12, 2016 14:41
Show Gist options
  • Save jpmartha/986c9a3e432532df2faa3cb12076a09f to your computer and use it in GitHub Desktop.
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
#!/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
@jpmartha
Copy link
Author

2016-04-12 23 02 49


# An Existing Package's README.md

2016-04-12 22 43 05


# A New Package's README.md

2016-04-12 22 53 11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment