Created
May 16, 2017 19:40
-
-
Save tkissing/ac288b97412251bf8c915f109ae070bb to your computer and use it in GitHub Desktop.
Bash function to clone a repo into ~/Stash/${PROJECT}/${REPO} and run `npm i` in it all in one go (pass clone URL as argument)
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
stashclone() { | |
if [[ "${1}" =~ \/([^\/]+)\/([^\/]+).git$ ]]; then | |
PROJ=`echo "${BASH_REMATCH[1]}" | awk '{ print toupper($1); }'` | |
REPO="${BASH_REMATCH[2]}" | |
PDIR="${HOME}/Stash/${PROJ}" | |
RDIR="${PDIR}/${REPO}" | |
if [ -d "${RDIR}" ]; then | |
echo "${RDIR} is already there" | |
else | |
OWD=`pwd` | |
if [ ! -d "${PDIR}" ]; then | |
mkdir -p "$PDIR" | |
fi | |
cd "${PDIR}" | |
git clone "${1}" | |
cd "${RDIR}" | |
npm i | |
cd "${OWD}" | |
echo "Cloned into ${RDIR} and ran npm install" | |
fi | |
else | |
echo "Invalid input" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment