()
| 35 | } |
| 36 | |
| 37 | export async function backupTerminalPreferences(): Promise<string | null> { |
| 38 | const terminalPlistPath = getTerminalPlistPath() |
| 39 | const backupPath = `${terminalPlistPath}.bak` |
| 40 | |
| 41 | try { |
| 42 | const { code } = await execFileNoThrow('defaults', [ |
| 43 | 'export', |
| 44 | 'com.apple.Terminal', |
| 45 | terminalPlistPath, |
| 46 | ]) |
| 47 | |
| 48 | if (code !== 0) { |
| 49 | return null |
| 50 | } |
| 51 | |
| 52 | try { |
| 53 | await stat(terminalPlistPath) |
| 54 | } catch { |
| 55 | return null |
| 56 | } |
| 57 | |
| 58 | await execFileNoThrow('defaults', [ |
| 59 | 'export', |
| 60 | 'com.apple.Terminal', |
| 61 | backupPath, |
| 62 | ]) |
| 63 | |
| 64 | markTerminalSetupInProgress(backupPath) |
| 65 | |
| 66 | return backupPath |
| 67 | } catch (error) { |
| 68 | logError(error) |
| 69 | return null |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | type RestoreResult = |
| 74 | | { |
no test coverage detected