Skip to content

Instantly share code, notes, and snippets.

@SJROHRXD
Last active April 19, 2023 05:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SJROHRXD/d0e2aa1af0ad0f4de1aae869547892be to your computer and use it in GitHub Desktop.
Save SJROHRXD/d0e2aa1af0ad0f4de1aae869547892be to your computer and use it in GitHub Desktop.
πŸ’Ύ VS Code Trix - Bash Script (Windows) to Save Settings (Settings, Keybindings, Extensions List)

VS Code Trix - Bash Script (Windows) to Save Settings (Settings, Keybindings, Extensions List)

Path to the VS Code settings directory πŸ“‚

VSCODE_SETTINGS_DIR="$APPDATA/Code/User"

Create backup directory if it doesn't exist πŸ”

BACKUP_DIR="$HOME/vscode_settings_backup"
if [ ! -d "$BACKUP_DIR" ]; then
  mkdir "$BACKUP_DIR"
fi

Save ✨ extensions list to a file

EXTENSIONS_FILE="$BACKUP_DIR/extensions.txt"
code --list-extensions > "$EXTENSIONS_FILE"
echo "Extensions list saved to $EXTENSIONS_FILE"

Save 🏑 settings JSON to a file

SETTINGS_FILE="$BACKUP_DIR/settings.json"
if [ -f "$VSCODE_SETTINGS_DIR/settings.json" ]; then
  cp "$VSCODE_SETTINGS_DIR/settings.json" "$SETTINGS_FILE"
  echo "Settings JSON saved to $SETTINGS_FILE"
else
  echo "Error: Could not find settings.json in $VSCODE_SETTINGS_DIR"
  ERRORS=true
fi

Save πŸ” keybindings JSON to a file

KEYBINDINGS_FILE="$BACKUP_DIR/keybindings.json"
if [ -f "$VSCODE_SETTINGS_DIR/keybindings.json" ]; then
  cp "$VSCODE_SETTINGS_DIR/keybindings.json" "$KEYBINDINGS_FILE"
  echo "Keybindings JSON saved to $KEYBINDINGS_FILE"
else
  echo "Error: Could not find keybindings.json in $VSCODE_SETTINGS_DIR"
  ERRORS=true
fi

Print final message if no errors occurred βœ…

if [ "$ERRORS" = true ]; then
  echo "Some errors occurred during the backup process."
else
  echo "VS Code settings saved!"
fi

Open Explorer to folder πŸ“

explorer "C:\Users\it_me\vscode_settings_backup"
@SJROHRXD
Copy link
Author

SJROHRXD commented Apr 19, 2023

Note: Bash comments should look like this:

# Sorry about the markdown formatting lol

🀍 SJRXD

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