51 lines
2.2 KiB
Bash
51 lines
2.2 KiB
Bash
#!/usr/bin/env sh
|
|
set -eu
|
|
|
|
source_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
target="${XDG_CONFIG_HOME:-$HOME/.config}/zed"
|
|
timestamp=$(date +%Y%m%d-%H%M%S)
|
|
backup="$target/backups/portable-install-$timestamp"
|
|
|
|
mkdir -p "$target/scripts" "$backup"
|
|
for name in settings.json keymap.json tasks.json; do
|
|
if [ -f "$target/$name" ]; then
|
|
cp "$target/$name" "$backup/$name"
|
|
fi
|
|
done
|
|
|
|
cp "$source_dir/settings.json" "$target/settings.json"
|
|
cp "$source_dir/keymap.json" "$target/keymap.json"
|
|
cp "$source_dir/scripts/toggle-file-scan-exclusions.mjs" "$target/scripts/toggle-file-scan-exclusions.mjs"
|
|
cp "$source_dir/scripts/file-exclusions.json" "$target/scripts/file-exclusions.json"
|
|
cp "$source_dir/scripts/zed-settings-sync.mjs" "$target/scripts/zed-settings-sync.mjs"
|
|
if [ ! -f "$target/scripts/settings-sync.json" ]; then
|
|
cp "$source_dir/scripts/settings-sync.json" "$target/scripts/settings-sync.json"
|
|
fi
|
|
|
|
node - "$target/scripts/settings-sync.json" <<'NODE_STATE'
|
|
const fs = require("node:fs");
|
|
const statePath = process.argv[2];
|
|
const source = JSON.parse(fs.readFileSync(statePath, "utf8"));
|
|
const state = {
|
|
gist_id: typeof source.gist_id === "string" ? source.gist_id : "",
|
|
last_synced_hash: typeof source.last_synced_hash === "string" ? source.last_synced_hash : "",
|
|
auto_sync: source.auto_sync === true,
|
|
interval_minutes: Number.isInteger(source.interval_minutes) && source.interval_minutes >= 5 ? source.interval_minutes : 15,
|
|
last_run_at: typeof source.last_run_at === "string" ? source.last_run_at : "",
|
|
last_result: typeof source.last_result === "string" ? source.last_result : "",
|
|
};
|
|
fs.writeFileSync(statePath, `${JSON.stringify(state, null, 2)}\n`, "utf8");
|
|
NODE_STATE
|
|
|
|
node - "$source_dir/tasks.json" "$target/tasks.json" "$target/scripts/toggle-file-scan-exclusions.mjs" "$target/scripts/zed-settings-sync.mjs" <<'NODE'
|
|
const fs = require("node:fs");
|
|
const [source, target, toggleScript, syncScript] = process.argv.slice(2);
|
|
const tasks = fs.readFileSync(source, "utf8")
|
|
.replaceAll("__TOGGLE_SCRIPT__", toggleScript)
|
|
.replaceAll("__SYNC_SCRIPT__", syncScript);
|
|
fs.writeFileSync(target, tasks);
|
|
NODE
|
|
|
|
printf 'Installed Zed configuration to %s\n' "$target"
|
|
printf 'Previous configuration backed up to %s\n' "$backup"
|