Skip to content

Instantly share code, notes, and snippets.

@joshuamorony
Created August 30, 2022 04:24
Show Gist options
  • Save joshuamorony/9a73a2c033014c754c81d8dc3e49ba54 to your computer and use it in GitHub Desktop.
Save joshuamorony/9a73a2c033014c754c81d8dc3e49ba54 to your computer and use it in GitHub Desktop.
Alias for creating playground applications and sharing to GitHub/StackBlitz
resetAndOpen(){
git switch main --discard-changes
git reset --hard
git clean -fd
code .
}
createGitRepo(){
read -q "REPLY?Are you sure you want to share this publicly? "
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
local sourcePath=`pwd`
rsync -r --exclude=.git --exclude=node_modules . ~/Dev/playground/shared/$1
cd ~/Dev/playground/shared/$1
git init
git add .
git commit -m 'initial commit'
gh repo create $1 --public --push --source=. --remote=upstream
read -q "REPLY?Do you also want to create a StackBlitz? "
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
open "https://stackblitz.com/github/YOUR-GITHUB-USERNAME/$1"
else
gh repo view -w
fi
echo "Copy created at $(pwd), remaining in original directory"
cd $sourcePath
fi
}
share(){
if [ -z "$1" ]; then
read "NAME?What would you like to call this repo? "
echo
createGitRepo "$NAME"
else
createGitRepo "$1"
fi
}
alias play-angular="cd ~/Dev/testing/angular && resetAndOpen && ng serve"
alias play-ionic="cd ~/Dev/testing/ionic && git checkout -- . && code . && ionic serve"
alias play-nx="cd ~/Dev/testing/nx && git checkout -- . && code ."
@javieranguloluna
Copy link

It's a great idea for playing and sharing. It could be a top downloads vscode plugin!!!

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