Skip to content

Instantly share code, notes, and snippets.

@tkissing
Created May 16, 2017 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkissing/ac288b97412251bf8c915f109ae070bb to your computer and use it in GitHub Desktop.
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)
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