Created
July 17, 2024 19:47
-
-
Save foxoman/07105e1d309a39594cacb0c4454d6f53 to your computer and use it in GitHub Desktop.
Shell script to update my nim Zed extestion in Zed Editor PM with one click
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
#!/bin/bash | |
# Set the extension name | |
EXTENSION_NAME="nim" | |
# Set the new version (edit this manually) | |
NEW_VERSION="0.0.2" | |
# Set the original repo URL | |
ORIGINAL_REPO="https://github.com/foxoman/zed-nim" | |
# Set the Zed extensions repo URL | |
ZED_EXTENSIONS_REPO="zed-industries/extensions" | |
# Set your GitHub username | |
YOUR_GITHUB_USERNAME="foxoman" | |
# Function to check if a command was successful | |
check_success() { | |
if [ $? -ne 0 ]; then | |
echo "Error: $1" | |
exit 1 | |
fi | |
} | |
# 1. Check if gh is installed, if not install it | |
if ! command -v gh &> /dev/null; then | |
echo "GitHub CLI is not installed. Installing now..." | |
sudo apt update | |
sudo apt install -y gh | |
check_success "Failed to install GitHub CLI" | |
else | |
echo "GitHub CLI is already installed." | |
fi | |
# 2. Fork the Zed extensions repository to your account if not already forked | |
echo "Forking Zed extensions repository to your account if not already forked..." | |
gh repo fork ${ZED_EXTENSIONS_REPO} --clone=false | |
check_success "Failed to fork repository" | |
# 3. Clone your forked repository | |
if [ ! -d "extensions" ]; then | |
echo "Cloning your forked Zed extensions repository..." | |
gh repo clone ${YOUR_GITHUB_USERNAME}/extensions | |
check_success "Failed to clone repository" | |
cd extensions | |
else | |
echo "Extensions directory already exists. Updating..." | |
cd extensions | |
git fetch origin | |
git checkout main | |
git reset --hard origin/main | |
fi | |
# Ensure the upstream remote exists and fetch latest changes | |
git remote add upstream https://github.com/${ZED_EXTENSIONS_REPO}.git 2>/dev/null || true | |
git fetch upstream | |
git rebase upstream/main | |
# 4. Update only the Nim extension submodule from the original repo | |
echo "Updating ${EXTENSION_NAME} extension submodule..." | |
git submodule update --init -- extensions/${EXTENSION_NAME} | |
cd extensions/${EXTENSION_NAME} | |
git fetch ${ORIGINAL_REPO} | |
git checkout main | |
git pull ${ORIGINAL_REPO} main | |
check_success "Failed to update submodule" | |
cd ../.. | |
# 5. Open extensions.toml in Zed editor for manual editing | |
echo "Please open extensions.toml in Zed editor and update the Nim extension version to ${NEW_VERSION}." | |
zed extensions.toml | |
# 6. Wait for user to finish editing | |
echo "Press Enter when you've finished editing and closed the file." | |
read -p "Press Enter to continue..." | |
# Commit the changes | |
echo "Committing changes..." | |
git add extensions/${EXTENSION_NAME} extensions.toml | |
git commit -m "Update ${EXTENSION_NAME} extension to version ${NEW_VERSION}" | |
check_success "Failed to commit changes" | |
# Create a new branch | |
BRANCH_NAME="update-${EXTENSION_NAME}-extension-${NEW_VERSION}" | |
echo "Creating new branch: ${BRANCH_NAME}" | |
git checkout -b ${BRANCH_NAME} | |
check_success "Failed to create new branch" | |
# Push changes to your fork | |
echo "Pushing changes to your fork..." | |
git push -u origin ${BRANCH_NAME} --force | |
check_success "Failed to push changes" | |
# Create a pull request from your fork to the original Zed extensions repo | |
echo "Creating pull request from your fork to the Zed extensions repository..." | |
gh pr create --repo ${ZED_EXTENSIONS_REPO} --base main --head ${YOUR_GITHUB_USERNAME}:${BRANCH_NAME} --title "Update ${EXTENSION_NAME} extension to version ${NEW_VERSION}" --body "This PR updates the ${EXTENSION_NAME} extension submodule to version ${NEW_VERSION} and updates the version in extensions.toml" | |
check_success "Failed to create pull request" | |
echo "Process completed successfully!" | |
echo "A pull request has been created from your fork to the Zed extensions repository: https://github.com/${ZED_EXTENSIONS_REPO}/pulls" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment