Files
orcs-code/src/utils/iTermBackup.ts
did:key:z6MkqDnb7Siv3Cwj7pGJq4T5EsUisECqR8KpnDLwcaZq5TPr d2542c9a62 asdf
Squash the current repository state back into one baseline commit while
preserving the README reframing and repository contents.

Constraint: User explicitly requested a single squashed commit with subject "asdf"
Confidence: high
Scope-risk: broad
Reversibility: clean
Directive: This commit intentionally rewrites published history; coordinate before future force-pushes
Tested: git status clean; local history rewritten to one commit; force-pushed main to origin and instructkr
Not-tested: Fresh clone verification after push
2026-03-31 03:34:03 -07:00

74 lines
1.6 KiB
TypeScript

import { copyFile, stat } from 'fs/promises'
import { homedir } from 'os'
import { join } from 'path'
import { getGlobalConfig, saveGlobalConfig } from './config.js'
import { logError } from './log.js'
export function markITerm2SetupComplete(): void {
saveGlobalConfig(current => ({
...current,
iterm2SetupInProgress: false,
}))
}
function getIterm2RecoveryInfo(): {
inProgress: boolean
backupPath: string | null
} {
const config = getGlobalConfig()
return {
inProgress: config.iterm2SetupInProgress ?? false,
backupPath: config.iterm2BackupPath || null,
}
}
function getITerm2PlistPath(): string {
return join(
homedir(),
'Library',
'Preferences',
'com.googlecode.iterm2.plist',
)
}
type RestoreResult =
| {
status: 'restored' | 'no_backup'
}
| {
status: 'failed'
backupPath: string
}
export async function checkAndRestoreITerm2Backup(): Promise<RestoreResult> {
const { inProgress, backupPath } = getIterm2RecoveryInfo()
if (!inProgress) {
return { status: 'no_backup' }
}
if (!backupPath) {
markITerm2SetupComplete()
return { status: 'no_backup' }
}
try {
await stat(backupPath)
} catch {
markITerm2SetupComplete()
return { status: 'no_backup' }
}
try {
await copyFile(backupPath, getITerm2PlistPath())
markITerm2SetupComplete()
return { status: 'restored' }
} catch (restoreError) {
logError(
new Error(`Failed to restore iTerm2 settings with: ${restoreError}`),
)
markITerm2SetupComplete()
return { status: 'failed', backupPath }
}
}