refactor: final architecture audit and hardening
This commit is contained in:
@@ -1,39 +1,20 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Sync Nomarchy theme to VS Code, VSCodium, and Cursor
|
||||
# Nomarchy VS Code Theme Setter
|
||||
# This script only updates the global state.json.
|
||||
# Home Manager (modules/home/vscode.nix) handles the declarative settings injection.
|
||||
|
||||
VS_CODE_THEME="$HOME/.config/nomarchy/current/theme/vscode.json"
|
||||
STATE_DIR="$HOME/.config/home-manager"
|
||||
STATE_FILE="$STATE_DIR/state.json"
|
||||
|
||||
set_theme() {
|
||||
local editor_cmd="$1"
|
||||
local settings_path="$2"
|
||||
mkdir -p "$STATE_DIR"
|
||||
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
|
||||
|
||||
nomarchy-cmd-present "$editor_cmd" && [[ $NNOMARCHY_TOGGLE_SKIP_VSCODE_THEME != "true" ]] || return 0
|
||||
# Theme is already set in state.json by nomarchy-theme-set.
|
||||
# This script is now mostly a placeholder to maintain the same workflow,
|
||||
# triggering an env-update if needed to apply the declarative changes.
|
||||
|
||||
if [[ -f $VS_CODE_THEME ]]; then
|
||||
theme_name=$(jq -r '.name' "$VS_CODE_THEME")
|
||||
extension=$(jq -r '.extension' "$VS_CODE_THEME")
|
||||
|
||||
if [[ -n $extension ]] && ! "$editor_cmd" --list-extensions | grep -Fxq "$extension"; then
|
||||
"$editor_cmd" --install-extension "$extension" >/dev/null
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$settings_path")"
|
||||
[[ -f $settings_path ]] || printf '{\n}\n' >"$settings_path"
|
||||
|
||||
if ! grep -q '"workbench.colorTheme"' "$settings_path"; then
|
||||
sed -i --follow-symlinks -E '0,/\{/{s/\{/{\ "workbench.colorTheme": "",/}' "$settings_path"
|
||||
fi
|
||||
|
||||
sed -i --follow-symlinks -E \
|
||||
"s/(\"workbench.colorTheme\"[[:space:]]*:[[:space:]]*\")[^\"]*(\")/\1$theme_name\2/" \
|
||||
"$settings_path"
|
||||
elif [[ -f $settings_path ]]; then
|
||||
sed -i --follow-symlinks -E 's/\"workbench\.colorTheme\"[[:space:]]*:[^,}]*,?//' "$settings_path"
|
||||
fi
|
||||
}
|
||||
|
||||
set_theme "code" "$HOME/.config/Code/User/settings.json"
|
||||
set_theme "code-insiders" "$HOME/.config/Code - Insiders/User/settings.json"
|
||||
set_theme "codium" "$HOME/.config/VSCodium/User/settings.json"
|
||||
set_theme "cursor" "$HOME/.config/Cursor/User/settings.json"
|
||||
if [[ $NOMARCHY_TOGGLE_SKIP_VSCODE_THEME != "true" ]]; then
|
||||
# We trigger env-update to apply the new VSCode theme declaratively.
|
||||
env-update
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user