Created
March 15, 2024 21:42
-
-
Save slaughtr/cff093c383d71868d6bf4fbfe88437eb to your computer and use it in GitHub Desktop.
mupen
This file contains hidden or 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
# Thanks chat gippity! | |
# This zsh function simplifies jumping around many repos. And single repos, too | |
# It attempts to checkout the current dir's git repo main branch, fetch and pull, and open the directory in VS Code | |
# If there are unstaged changes in the current branch, it shows a diff and asks y/n if you want to discard those changes | |
# If yes, it continues as normal (checkout main, fetch, pull, VSC). If no, it aborts | |
# Why "mupen"? It's some amalgamation of main, pull, and open :shrug: | |
# Define the function | |
mupen() { | |
# Attempt to checkout the main branch. If there are no changes, this will succeed. | |
git checkout main &>/dev/null && { | |
echo "Switched to main branch successfully." | |
git fetch && git pull | |
code . | |
return | |
} | |
# If the checkout fails, it might be due to unstaged changes. Check for unstaged changes. | |
if ! git diff --exit-code --quiet; then | |
echo "Unstaged changes detected." | |
git diff | |
# Ask the user if they want to discard the changes. | |
read "response?Do you want to discard these changes? [y/N]: " | |
if [[ "$response" =~ ^[Yy]$ ]]; then | |
# Discard the changes | |
git checkout -- . | |
else | |
# Exit if the user doesn't want to discard the changes. | |
echo "Exiting without discarding changes." | |
return | |
fi | |
fi | |
# Checkout the main branch, fetch and pull updates, and open VS Code. | |
git checkout main | |
git fetch && git pull | |
echo "Switched to main branch and updated." | |
code . | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment