#!/usr/bin/env bash

# omarchy:summary=Install VSCodium, the telemetry-free VS Code build
# omarchy:requires-sudo=true

# Based: VSCodium comes from Flathub on Debian and from its cask on macOS.
# Its product.json points the extension gallery at Microsoft's marketplace,
# as the former dev tooling did, then settings.json and keybindings.json land
# where this OS's VSCodium reads them.

set -eo pipefail

echo "Installing VSCodium..."
omarchy-pkg-add codium flatpak=com.vscodium.codium cask=vscodium

user_dir=$(omarchy-code-config-dir codium)
mkdir -p "$user_dir"
[[ -e $user_dir/keybindings.json ]] || cp "$OMARCHY_PATH/config/code/User/keybindings.json" "$user_dir/keybindings.json"
[[ -e $user_dir/settings.json ]] || cp "$OMARCHY_PATH/config/code/User/settings.json" "$user_dir/settings.json"

product_json=${user_dir%/User}/product.json
[[ -e $product_json ]] || cat >"$product_json" <<'PRODUCT'
{
	"extensionsGallery": {
		"serviceUrl": "https://marketplace.visualstudio.com/_apis/public/gallery",
		"cacheUrl": "https://vscode.blob.core.windows.net/gallery/index",
		"itemUrl": "https://marketplace.visualstudio.com/items",
		"controlUrl": "",
		"recommendationsUrl": ""
	}
}
PRODUCT

omarchy-code-extensions ahmadalli.vscode-nginx-conf anysphere.remote-ssh eamodio.gitlens editorconfig.editorconfig \
  gruntfuggly.todo-tree kisstkondoros.vscode-gutter-preview mechatroner.rainbow-csv mikestead.dotenv mkhl.direnv \
  ms-vscode.hexeditor ms-vscode.makefile-tools naumovs.color-highlight psioniq.psi-header redhat.vscode-xml \
  redhat.vscode-yaml streetsidesoftware.code-spell-checker ultram4rine.vscode-choosealicense vspacecode.vspacecode \
  vspacecode.whichkey zawys.vscode-as-git-mergetool
