Skip to content

Instantly share code, notes, and snippets.

@josephgoksu
Last active July 5, 2024 11:34
Show Gist options
  • Save josephgoksu/e4a55939fe727955c69a1786dea5ae3a to your computer and use it in GitHub Desktop.
Save josephgoksu/e4a55939fe727955c69a1786dea5ae3a to your computer and use it in GitHub Desktop.
This bash script automates the process of switching from Visual Studio Code (VSCode) or VSCode Insiders to VSCodium on macOS
#!/bin/bash
# Check if running on macOS
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "This script is designed to run on macOS."
exit 1
fi
# Function to check if a cask is installed
is_cask_installed() {
brew list --cask "$1" &>/dev/null
}
# Step 1 — Check if Homebrew is installed
if ! command -v brew &>/dev/null; then
echo "Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
else
echo "Homebrew is already installed."
fi
# Step 2 — Install VSCodium if not already installed
if ! is_cask_installed "vscodium"; then
echo "Installing VSCodium..."
brew install --cask vscodium
else
echo "VSCodium is already installed."
fi
# Step 3 — Check for VSCode or VSCode Insiders settings and extensions
VSCODE_SETTINGS_DIR=""
VSCODE_COMMAND=""
if [ -d "$HOME/Library/Application Support/Code - Insiders/User" ]; then
VSCODE_SETTINGS_DIR="$HOME/Library/Application Support/Code - Insiders/User"
VSCODE_COMMAND="code-insiders"
elif [ -d "$HOME/Library/Application Support/Code/User" ]; then
VSCODE_SETTINGS_DIR="$HOME/Library/Application Support/Code/User"
VSCODE_COMMAND="code"
else
echo "VSCode or VSCode Insiders settings not found."
exit 1
fi
# Step 4 — Export VSCode settings and extensions
echo "Exporting VSCode settings and extensions..."
cp "$VSCODE_SETTINGS_DIR/settings.json" ~/vscode-settings.json
cp "$VSCODE_SETTINGS_DIR/keybindings.json" ~/vscode-keybindings.json
$VSCODE_COMMAND --list-extensions | tee ~/vscode-extensions.txt
# Step 5 — Reinstall extensions for VSCodium
echo "Reinstalling extensions for VSCodium..."
xargs -n1 codium --install-extension <~/vscode-extensions.txt
# Step 6 — Import settings for VSCodium
echo "Importing settings for VSCodium..."
mkdir -p "$HOME/Library/Application Support/VSCodium/User"
mv ~/vscode-settings.json "$HOME/Library/Application Support/VSCodium/User/settings.json"
mv ~/vscode-keybindings.json "$HOME/Library/Application Support/VSCodium/User/keybindings.json"
# Step 7 — Remove VSCode or VSCode Insiders if everything was successful
echo "Removing VSCode or VSCode Insiders..."
if is_cask_installed "visual-studio-code"; then
brew uninstall --cask visual-studio-code
elif is_cask_installed "visual-studio-code-insiders"; then
brew uninstall --cask visual-studio-code-insiders
fi
echo "Switch to VSCodium completed successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment