MCPcopy
hub / github.com/codeaashu/claude-code / checkAndRestoreTerminalBackup

Function checkAndRestoreTerminalBackup

src/utils/appleTerminalBackup.ts:82–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

80 }
81
82export async function checkAndRestoreTerminalBackup(): Promise<RestoreResult> {
83 const { inProgress, backupPath } = getTerminalRecoveryInfo()
84 if (!inProgress) {
85 return { status: 'no_backup' }
86 }
87
88 if (!backupPath) {
89 markTerminalSetupComplete()
90 return { status: 'no_backup' }
91 }
92
93 try {
94 await stat(backupPath)
95 } catch {
96 markTerminalSetupComplete()
97 return { status: 'no_backup' }
98 }
99
100 try {
101 const { code } = await execFileNoThrow('defaults', [
102 'import',
103 'com.apple.Terminal',
104 backupPath,
105 ])
106
107 if (code !== 0) {
108 return { status: 'failed', backupPath }
109 }
110
111 await execFileNoThrow('killall', ['cfprefsd'])
112
113 markTerminalSetupComplete()
114 return { status: 'restored' }
115 } catch (restoreError) {
116 logError(
117 new Error(
118 `Failed to restore Terminal.app settings with: ${restoreError}`,
119 ),
120 )
121 markTerminalSetupComplete()
122 return { status: 'failed', backupPath }
123 }
124}
125

Callers 2

setupFunction · 0.85

Calls 5

getTerminalRecoveryInfoFunction · 0.85
statFunction · 0.85
execFileNoThrowFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected