mux-sesh 1.4.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -7
- package/package.json +3 -3
- package/src/app.tsx +746 -173
- package/src/components/KeybindHelp.tsx +178 -111
- package/src/config/index.ts +413 -20
- package/src/config/listed-sessions.ts +36 -0
- package/src/config/session-rules.ts +101 -0
- package/src/handlers/actions.ts +93 -6
- package/src/handlers/keyboard.ts +299 -79
- package/src/items/order.ts +50 -0
- package/src/opencode/session.ts +1 -17
- package/src/opencode/stats.ts +1 -1
- package/src/preview/project.ts +235 -0
- package/src/projects/session-links.ts +31 -0
- package/src/search/index.ts +83 -47
- package/src/settings.ts +425 -0
- package/src/styles/opencode-themes-a.ts +1 -0
- package/src/styles/opencode-themes-b.ts +1 -0
- package/src/styles/theme.tsx +441 -0
- package/src/tmux/index.ts +58 -14
- package/src/tmux/projects.ts +151 -20
- package/src/tmux/workflows.ts +22 -0
- package/src/types/index.ts +114 -0
- package/src/ui/CommandsModal.tsx +145 -0
- package/src/ui/HighlightedText.tsx +6 -3
- package/src/ui/ItemList.tsx +47 -41
- package/src/ui/Modal.tsx +41 -0
- package/src/ui/OpencodeSessionGroup.tsx +50 -46
- package/src/ui/OpencodeStatsPanel.tsx +34 -39
- package/src/ui/RenameModal.tsx +42 -0
- package/src/ui/SearchInput.tsx +3 -1
- package/src/ui/SessionDetailsPanel.tsx +168 -72
- package/src/ui/SessionList.tsx +59 -34
- package/src/ui/SessionStats.tsx +5 -3
- package/src/ui/SettingEditorModal.tsx +49 -0
- package/src/ui/SettingOptionsModal.tsx +77 -0
- package/src/ui/SettingsModal.tsx +96 -0
- package/src/ui/Toast.tsx +8 -9
- package/src/ui/item-icon.ts +78 -0
- package/src/ui/list-window.ts +22 -0
- package/src/update/installation.ts +4 -15
- package/src/update/version.ts +2 -1
- package/src/util/glob.ts +47 -0
- package/src/util/terminal.ts +6 -20
- package/src/styles/theme.ts +0 -50
package/src/config/index.ts
CHANGED
|
@@ -1,39 +1,432 @@
|
|
|
1
1
|
import { join } from 'path'
|
|
2
2
|
import { mkdir } from 'fs/promises'
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
Config,
|
|
5
|
+
IconConfig,
|
|
6
|
+
KeybindMode,
|
|
7
|
+
ProjectProfile,
|
|
8
|
+
ProjectWildcard,
|
|
9
|
+
SessionDefaults,
|
|
10
|
+
SortOrder,
|
|
11
|
+
ThemeColorScheme,
|
|
12
|
+
ThemeDefinition,
|
|
13
|
+
ThemePalette,
|
|
14
|
+
ThemeVariant,
|
|
15
|
+
ZoxideMode,
|
|
16
|
+
} from '../types'
|
|
17
|
+
|
|
18
|
+
const DEFAULT_EDITOR = 'nvim'
|
|
19
|
+
const DEFAULT_THEME = 'rosepine'
|
|
20
|
+
const DEFAULT_COLOR_SCHEME: ThemeColorScheme = 'system'
|
|
21
|
+
const DEFAULT_PREFIX_KEY = 'ctrl+x'
|
|
22
|
+
const DEFAULT_EDITOR_COMMAND =
|
|
23
|
+
"nvim -c \"lua vim.defer_fn(function() if pcall(require, 'telescope') then vim.cmd('Telescope find_files') end end, 100)\""
|
|
24
|
+
const DEFAULT_ICONS: IconConfig = {
|
|
25
|
+
tmux: '',
|
|
26
|
+
configured: '',
|
|
27
|
+
project: '',
|
|
28
|
+
opencode: '',
|
|
29
|
+
}
|
|
30
|
+
const OPTIONAL_THEME_PALETTE_KEYS = ['accent', 'interactive', 'diffAdd', 'diffDelete'] as const
|
|
31
|
+
|
|
32
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
33
|
+
return typeof value === 'object' && value !== null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function asString(value: unknown): string | undefined {
|
|
37
|
+
return typeof value === 'string' && value.length > 0 ? value : undefined
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function asBoolean(value: unknown): boolean | undefined {
|
|
41
|
+
return typeof value === 'boolean' ? value : undefined
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function asStringArray(value: unknown): string[] | undefined {
|
|
45
|
+
if (!Array.isArray(value)) {
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const strings = value.filter((entry): entry is string => typeof entry === 'string' && entry.length > 0)
|
|
50
|
+
return strings.length > 0 ? strings : undefined
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function asKeybindMode(value: unknown): KeybindMode | undefined {
|
|
54
|
+
return value === 'vim' || value === 'standard' ? value : undefined
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function asZoxideMode(value: unknown): ZoxideMode | undefined {
|
|
58
|
+
return value === 'off' || value === 'rank' || value === 'merge' ? value : undefined
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function asSortOrder(value: unknown): SortOrder | undefined {
|
|
62
|
+
return value === 'live-first' || value === 'configured-first' || value === 'zoxide-first' || value === 'alphabetical'
|
|
63
|
+
? value
|
|
64
|
+
: undefined
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function asThemeColorScheme(value: unknown): ThemeColorScheme | undefined {
|
|
68
|
+
return value === 'light' || value === 'dark' || value === 'system' ? value : undefined
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function asPositiveInteger(value: unknown): number | undefined {
|
|
72
|
+
return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : undefined
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function expandHomePath(value: string, homeDir: string): string {
|
|
76
|
+
if (!value.startsWith('~')) {
|
|
77
|
+
return value
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return join(homeDir, value.slice(1))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function normalizeSessionDefaults(value: unknown): SessionDefaults | undefined {
|
|
84
|
+
if (!isRecord(value)) {
|
|
85
|
+
return undefined
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const startupCommand = asString(value.startup_command) ?? asString(value.startupCommand)
|
|
89
|
+
const previewCommand = asString(value.preview_command) ?? asString(value.previewCommand)
|
|
90
|
+
|
|
91
|
+
if (!startupCommand && !previewCommand) {
|
|
92
|
+
return undefined
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
startupCommand,
|
|
97
|
+
previewCommand,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function normalizeIcons(value: unknown): IconConfig | undefined {
|
|
102
|
+
if (!isRecord(value)) {
|
|
103
|
+
return undefined
|
|
104
|
+
}
|
|
4
105
|
|
|
5
|
-
|
|
6
|
-
|
|
106
|
+
return {
|
|
107
|
+
tmux: asString(value.tmux) ?? DEFAULT_ICONS.tmux,
|
|
108
|
+
configured: asString(value.configured) ?? asString(value.config) ?? DEFAULT_ICONS.configured,
|
|
109
|
+
project: asString(value.project) ?? DEFAULT_ICONS.project,
|
|
110
|
+
opencode: asString(value.opencode) ?? DEFAULT_ICONS.opencode,
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function normalizeThemePalette(value: unknown): ThemePalette | undefined {
|
|
115
|
+
if (!isRecord(value)) {
|
|
116
|
+
return undefined
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const neutral = asString(value.neutral)
|
|
120
|
+
const ink = asString(value.ink)
|
|
121
|
+
const primary = asString(value.primary)
|
|
122
|
+
const success = asString(value.success)
|
|
123
|
+
const warning = asString(value.warning)
|
|
124
|
+
const error = asString(value.error)
|
|
125
|
+
const info = asString(value.info)
|
|
126
|
+
|
|
127
|
+
if (!neutral || !ink || !primary || !success || !warning || !error || !info) {
|
|
128
|
+
return undefined
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const normalized: ThemePalette = {
|
|
132
|
+
neutral,
|
|
133
|
+
ink,
|
|
134
|
+
primary,
|
|
135
|
+
success,
|
|
136
|
+
warning,
|
|
137
|
+
error,
|
|
138
|
+
info,
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
for (const key of OPTIONAL_THEME_PALETTE_KEYS) {
|
|
142
|
+
const color = asString(value[key])
|
|
143
|
+
if (color) {
|
|
144
|
+
normalized[key] = color
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return normalized
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function normalizeThemeVariant(value: unknown): ThemeVariant | undefined {
|
|
152
|
+
if (!isRecord(value)) {
|
|
153
|
+
return undefined
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const palette = normalizeThemePalette(value.palette)
|
|
157
|
+
if (!palette) {
|
|
158
|
+
return undefined
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const overrides = isRecord(value.overrides)
|
|
162
|
+
? Object.fromEntries(
|
|
163
|
+
Object.entries(value.overrides)
|
|
164
|
+
.map(([key, override]) => [key, asString(override)])
|
|
165
|
+
.filter((entry): entry is [string, string] => typeof entry[1] === 'string')
|
|
166
|
+
)
|
|
167
|
+
: undefined
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
palette,
|
|
171
|
+
overrides: overrides && Object.keys(overrides).length > 0 ? overrides : undefined,
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function normalizeThemeDefinition(value: unknown, id: string): ThemeDefinition | undefined {
|
|
176
|
+
if (!isRecord(value)) {
|
|
177
|
+
return undefined
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const light = normalizeThemeVariant(value.light)
|
|
181
|
+
const dark = normalizeThemeVariant(value.dark)
|
|
182
|
+
|
|
183
|
+
if (!light || !dark) {
|
|
184
|
+
return undefined
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
name: asString(value.name) ?? id,
|
|
189
|
+
light,
|
|
190
|
+
dark,
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function normalizeThemes(value: unknown): Record<string, ThemeDefinition> | undefined {
|
|
195
|
+
if (!isRecord(value)) {
|
|
196
|
+
return undefined
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const entries = Object.entries(value).flatMap(([name, definition]) => {
|
|
200
|
+
const normalizedDefinition = normalizeThemeDefinition(definition, name)
|
|
201
|
+
if (!normalizedDefinition) {
|
|
202
|
+
return []
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return [[name, normalizedDefinition] as const]
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
return entries.length > 0 ? Object.fromEntries(entries) : undefined
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function normalizeProjectProfiles(value: unknown, homeDir: string): ProjectProfile[] | undefined {
|
|
212
|
+
if (!Array.isArray(value)) {
|
|
213
|
+
return undefined
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const profiles = value.flatMap(entry => {
|
|
217
|
+
if (!isRecord(entry)) {
|
|
218
|
+
return []
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const path = asString(entry.path)
|
|
222
|
+
if (!path) {
|
|
223
|
+
return []
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return [
|
|
227
|
+
{
|
|
228
|
+
path: expandHomePath(path, homeDir),
|
|
229
|
+
sessionName: asString(entry.session_name) ?? asString(entry.sessionName),
|
|
230
|
+
startupCommand: asString(entry.startup_command) ?? asString(entry.startupCommand),
|
|
231
|
+
previewCommand: asString(entry.preview_command) ?? asString(entry.previewCommand),
|
|
232
|
+
listed: asBoolean(entry.listed),
|
|
233
|
+
icon: asString(entry.icon),
|
|
234
|
+
},
|
|
235
|
+
]
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
return profiles.length > 0 ? profiles : undefined
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function normalizeWildcards(value: unknown, homeDir: string): ProjectWildcard[] | undefined {
|
|
242
|
+
if (!Array.isArray(value)) {
|
|
243
|
+
return undefined
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const wildcards = value.flatMap(entry => {
|
|
247
|
+
if (!isRecord(entry)) {
|
|
248
|
+
return []
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const pattern = asString(entry.pattern)
|
|
252
|
+
if (!pattern) {
|
|
253
|
+
return []
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return [
|
|
257
|
+
{
|
|
258
|
+
pattern: expandHomePath(pattern, homeDir),
|
|
259
|
+
sessionName: asString(entry.session_name) ?? asString(entry.sessionName),
|
|
260
|
+
startupCommand: asString(entry.startup_command) ?? asString(entry.startupCommand),
|
|
261
|
+
previewCommand: asString(entry.preview_command) ?? asString(entry.previewCommand),
|
|
262
|
+
},
|
|
263
|
+
]
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
return wildcards.length > 0 ? wildcards : undefined
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function normalizeConfig(rawConfig: unknown, homeDir = process.env.HOME || '~'): Config {
|
|
270
|
+
const raw = isRecord(rawConfig) ? rawConfig : {}
|
|
271
|
+
const defaultConfig = getDefaultConfig(homeDir)
|
|
272
|
+
const requestedTheme = asString(raw.theme)
|
|
273
|
+
const normalizedTheme =
|
|
274
|
+
requestedTheme === 'rose-pine'
|
|
275
|
+
? 'rosepine'
|
|
276
|
+
: requestedTheme === 'opencode-dark' || requestedTheme === 'opencode-light'
|
|
277
|
+
? 'opencode'
|
|
278
|
+
: requestedTheme
|
|
279
|
+
const implicitColorScheme =
|
|
280
|
+
requestedTheme === 'opencode-light' ? 'light' : requestedTheme === 'opencode-dark' ? 'dark' : undefined
|
|
281
|
+
|
|
282
|
+
const projectPaths = (asStringArray(raw.project_paths) ?? asStringArray(raw.projectPaths) ?? defaultConfig.projectPaths).map(
|
|
283
|
+
projectPath => expandHomePath(projectPath, homeDir)
|
|
284
|
+
)
|
|
285
|
+
const reposPath = expandHomePath(
|
|
286
|
+
asString(raw.repos_path) ?? asString(raw.reposPath) ?? defaultConfig.reposPath,
|
|
287
|
+
homeDir
|
|
288
|
+
)
|
|
289
|
+
const editor = asString(raw.editor) ?? defaultConfig.editor
|
|
290
|
+
const editorCmd = asString(raw.editor_cmd) ?? asString(raw.editorCmd) ?? defaultConfig.editorCmd
|
|
291
|
+
const keybindMode = asKeybindMode(raw.keybind_mode) ?? asKeybindMode(raw.keybindMode) ?? defaultConfig.keybindMode
|
|
292
|
+
const prefixKey = asString(raw.prefix_key) ?? asString(raw.prefixKey) ?? defaultConfig.prefixKey
|
|
293
|
+
const zoxideMode = asZoxideMode(raw.zoxide_mode) ?? asZoxideMode(raw.zoxideMode) ?? defaultConfig.zoxideMode
|
|
294
|
+
const sortOrder = asSortOrder(raw.sort_order) ?? asSortOrder(raw.sortOrder) ?? defaultConfig.sortOrder
|
|
295
|
+
const theme = normalizedTheme ?? defaultConfig.theme
|
|
296
|
+
const colorScheme =
|
|
297
|
+
asThemeColorScheme(raw.color_scheme) ??
|
|
298
|
+
asThemeColorScheme(raw.colorScheme) ??
|
|
299
|
+
implicitColorScheme ??
|
|
300
|
+
defaultConfig.colorScheme
|
|
301
|
+
const themes = normalizeThemes(raw.themes) ?? defaultConfig.themes
|
|
302
|
+
const autoUpdate = asBoolean(raw.auto_update) ?? asBoolean(raw.autoUpdate) ?? defaultConfig.autoUpdate
|
|
303
|
+
const dirLength = asPositiveInteger(raw.dir_length) ?? asPositiveInteger(raw.dirLength) ?? defaultConfig.dirLength
|
|
304
|
+
const hiddenSessions = asStringArray(raw.hidden_sessions) ?? asStringArray(raw.hiddenSessions) ?? defaultConfig.hiddenSessions
|
|
305
|
+
const icons = normalizeIcons(raw.icons) ?? defaultConfig.icons
|
|
306
|
+
const configuredDefaultSession = normalizeSessionDefaults(raw.default_session) ?? normalizeSessionDefaults(raw.defaultSession)
|
|
307
|
+
const defaultSession = {
|
|
308
|
+
startupCommand: configuredDefaultSession?.startupCommand ?? editorCmd,
|
|
309
|
+
previewCommand: configuredDefaultSession?.previewCommand,
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return {
|
|
313
|
+
projectPaths,
|
|
314
|
+
reposPath,
|
|
315
|
+
editor,
|
|
316
|
+
editorCmd,
|
|
317
|
+
keybindMode,
|
|
318
|
+
prefixKey,
|
|
319
|
+
zoxideMode,
|
|
320
|
+
sortOrder,
|
|
321
|
+
theme,
|
|
322
|
+
colorScheme,
|
|
323
|
+
themes,
|
|
324
|
+
autoUpdate,
|
|
325
|
+
dirLength,
|
|
326
|
+
hiddenSessions,
|
|
327
|
+
icons,
|
|
328
|
+
defaultSession,
|
|
329
|
+
projects: normalizeProjectProfiles(raw.projects, homeDir) ?? defaultConfig.projects,
|
|
330
|
+
wildcards: normalizeWildcards(raw.wildcards, homeDir) ?? defaultConfig.wildcards,
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export function getDefaultConfig(homeDir = process.env.HOME || '~'): Config {
|
|
7
335
|
return {
|
|
8
336
|
projectPaths: [join(homeDir, 'dev'), join(homeDir, 'personal')],
|
|
9
337
|
reposPath: join(homeDir, 'dev', 'repos'),
|
|
10
|
-
editor:
|
|
11
|
-
editorCmd:
|
|
12
|
-
"nvim -c \"lua vim.defer_fn(function() if pcall(require, 'telescope') then vim.cmd('Telescope find_files') end end, 100)\"",
|
|
338
|
+
editor: DEFAULT_EDITOR,
|
|
339
|
+
editorCmd: DEFAULT_EDITOR_COMMAND,
|
|
13
340
|
keybindMode: 'vim',
|
|
341
|
+
prefixKey: DEFAULT_PREFIX_KEY,
|
|
342
|
+
zoxideMode: 'off',
|
|
343
|
+
sortOrder: 'live-first',
|
|
344
|
+
theme: DEFAULT_THEME,
|
|
345
|
+
colorScheme: DEFAULT_COLOR_SCHEME,
|
|
346
|
+
themes: {},
|
|
14
347
|
autoUpdate: true,
|
|
348
|
+
dirLength: 1,
|
|
349
|
+
hiddenSessions: [],
|
|
350
|
+
icons: DEFAULT_ICONS,
|
|
351
|
+
defaultSession: {
|
|
352
|
+
startupCommand: DEFAULT_EDITOR_COMMAND,
|
|
353
|
+
},
|
|
354
|
+
projects: [],
|
|
355
|
+
wildcards: [],
|
|
15
356
|
}
|
|
16
357
|
}
|
|
17
358
|
|
|
359
|
+
function serializeThemeVariant(variant: ThemeVariant) {
|
|
360
|
+
return variant.overrides && Object.keys(variant.overrides).length > 0
|
|
361
|
+
? {
|
|
362
|
+
palette: variant.palette,
|
|
363
|
+
overrides: variant.overrides,
|
|
364
|
+
}
|
|
365
|
+
: {
|
|
366
|
+
palette: variant.palette,
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export function serializeConfig(config: Config): Record<string, unknown> {
|
|
371
|
+
return {
|
|
372
|
+
project_paths: config.projectPaths,
|
|
373
|
+
repos_path: config.reposPath,
|
|
374
|
+
editor: config.editor,
|
|
375
|
+
editor_cmd: config.editorCmd,
|
|
376
|
+
keybind_mode: config.keybindMode,
|
|
377
|
+
prefix_key: config.prefixKey,
|
|
378
|
+
zoxide_mode: config.zoxideMode,
|
|
379
|
+
sort_order: config.sortOrder,
|
|
380
|
+
theme: config.theme,
|
|
381
|
+
color_scheme: config.colorScheme,
|
|
382
|
+
auto_update: config.autoUpdate,
|
|
383
|
+
dir_length: config.dirLength,
|
|
384
|
+
hidden_sessions: config.hiddenSessions,
|
|
385
|
+
icons: config.icons,
|
|
386
|
+
default_session: config.defaultSession
|
|
387
|
+
? {
|
|
388
|
+
startup_command: config.defaultSession.startupCommand,
|
|
389
|
+
preview_command: config.defaultSession.previewCommand,
|
|
390
|
+
}
|
|
391
|
+
: undefined,
|
|
392
|
+
themes: config.themes
|
|
393
|
+
? Object.fromEntries(
|
|
394
|
+
Object.entries(config.themes).map(([id, theme]) => [
|
|
395
|
+
id,
|
|
396
|
+
{
|
|
397
|
+
name: theme.name,
|
|
398
|
+
light: serializeThemeVariant(theme.light),
|
|
399
|
+
dark: serializeThemeVariant(theme.dark),
|
|
400
|
+
},
|
|
401
|
+
])
|
|
402
|
+
)
|
|
403
|
+
: undefined,
|
|
404
|
+
projects: config.projects?.map(project => ({
|
|
405
|
+
path: project.path,
|
|
406
|
+
session_name: project.sessionName,
|
|
407
|
+
startup_command: project.startupCommand,
|
|
408
|
+
preview_command: project.previewCommand,
|
|
409
|
+
listed: project.listed,
|
|
410
|
+
icon: project.icon,
|
|
411
|
+
})),
|
|
412
|
+
wildcards: config.wildcards?.map(wildcard => ({
|
|
413
|
+
pattern: wildcard.pattern,
|
|
414
|
+
session_name: wildcard.sessionName,
|
|
415
|
+
startup_command: wildcard.startupCommand,
|
|
416
|
+
preview_command: wildcard.previewCommand,
|
|
417
|
+
})),
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
|
|
18
422
|
export async function loadConfig(): Promise<Config> {
|
|
19
423
|
const configDir = join(process.env.HOME!, '.config', 'mux-sesh')
|
|
20
424
|
const configPath = join(configDir, 'config.json')
|
|
21
425
|
|
|
22
426
|
try {
|
|
23
427
|
const file = Bun.file(configPath)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// Convert snake_case keys to camelCase for TypeScript
|
|
27
|
-
return {
|
|
28
|
-
...getDefaultConfig(),
|
|
29
|
-
projectPaths: config.project_paths || config.projectPaths,
|
|
30
|
-
reposPath: config.repos_path || config.reposPath,
|
|
31
|
-
editor: config.editor,
|
|
32
|
-
editorCmd: config.editor_cmd || config.editorCmd,
|
|
33
|
-
keybindMode: config.keybind_mode || config.keybindMode,
|
|
34
|
-
autoUpdate: config.auto_update || config.autoUpdate,
|
|
35
|
-
}
|
|
36
|
-
} catch (error) {
|
|
428
|
+
return normalizeConfig(await file.json(), process.env.HOME || '~')
|
|
429
|
+
} catch {
|
|
37
430
|
// Config doesn't exist, create default
|
|
38
431
|
const defaultConfig = getDefaultConfig()
|
|
39
432
|
await saveConfig(defaultConfig)
|
|
@@ -46,7 +439,7 @@ export async function saveConfig(config: Config): Promise<void> {
|
|
|
46
439
|
const configPath = join(configDir, 'config.json')
|
|
47
440
|
|
|
48
441
|
await mkdir(configDir, { recursive: true })
|
|
49
|
-
await Bun.write(configPath, JSON.stringify(config, null, 2))
|
|
442
|
+
await Bun.write(configPath, JSON.stringify(serializeConfig(config), null, 2))
|
|
50
443
|
}
|
|
51
444
|
|
|
52
445
|
export function getConfigPath(): string {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Config, Item, ProjectProfile } from '../types'
|
|
2
|
+
import { resolveProjectSession } from './session-rules'
|
|
3
|
+
|
|
4
|
+
function displayPath(path: string): string {
|
|
5
|
+
return path.replace(process.env.HOME || '', '~')
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function isListedProjectProfile(profile: ProjectProfile): boolean {
|
|
9
|
+
return profile.listed === true
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function getListedSessionItems(config: Config): Promise<Item[]> {
|
|
13
|
+
const listedProfiles = (config.projects ?? []).filter(isListedProjectProfile)
|
|
14
|
+
|
|
15
|
+
return Promise.all(
|
|
16
|
+
listedProfiles.map(async profile => {
|
|
17
|
+
const resolvedSession = await resolveProjectSession(profile.path, config)
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
title: resolvedSession.sessionName,
|
|
21
|
+
desc: displayPath(profile.path),
|
|
22
|
+
path: profile.path,
|
|
23
|
+
isSession: false,
|
|
24
|
+
itemKind: 'configured' as const,
|
|
25
|
+
icon: profile.icon,
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function mergeSessionItems(tmuxSessions: Item[], listedSessions: Item[]): Item[] {
|
|
32
|
+
const liveSessionTitles = new Set(tmuxSessions.map(item => item.title))
|
|
33
|
+
const uniqueListedSessions = listedSessions.filter(item => !liveSessionTitles.has(item.title))
|
|
34
|
+
|
|
35
|
+
return [...tmuxSessions, ...uniqueListedSessions]
|
|
36
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { basename } from 'path'
|
|
2
|
+
import { spawn } from 'bun'
|
|
3
|
+
import type { Config, ProjectProfile, ProjectWildcard } from '../types'
|
|
4
|
+
import { matchesGlob, normalizePathForMatching } from '../util/glob'
|
|
5
|
+
|
|
6
|
+
export interface ResolvedProjectSession {
|
|
7
|
+
sessionName: string
|
|
8
|
+
startupCommand?: string
|
|
9
|
+
previewCommand?: string
|
|
10
|
+
source: 'project' | 'wildcard' | 'default'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ResolveProjectSessionOptions {
|
|
14
|
+
getGitRoot?: (projectPath: string) => Promise<string | null>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function sanitizeSessionName(value: string): string {
|
|
18
|
+
return value.replace(/[.\s/]+/g, '_')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function pathMatches(projectPath: string, pattern: string): boolean {
|
|
22
|
+
return matchesGlob(normalizePathForMatching(projectPath), normalizePathForMatching(pattern), {
|
|
23
|
+
pathSeparatorAware: true,
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function findProjectProfile(projectPath: string, config: Config): ProjectProfile | undefined {
|
|
28
|
+
return config.projects?.find(profile => normalizePathForMatching(profile.path) === projectPath)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function findWildcard(projectPath: string, config: Config): ProjectWildcard | undefined {
|
|
32
|
+
return config.wildcards?.find(wildcard => pathMatches(projectPath, wildcard.pattern))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function getGitRoot(projectPath: string): Promise<string | null> {
|
|
36
|
+
try {
|
|
37
|
+
const proc = spawn(['git', '-C', projectPath, 'rev-parse', '--show-toplevel'], {
|
|
38
|
+
stderr: 'pipe',
|
|
39
|
+
})
|
|
40
|
+
const output = (await new Response(proc.stdout).text()).trim()
|
|
41
|
+
await proc.exited
|
|
42
|
+
|
|
43
|
+
if (proc.exitCode !== 0 || output.length === 0) {
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return output
|
|
48
|
+
} catch {
|
|
49
|
+
return null
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function buildSessionName(projectPath: string, dirLength = 1, gitRoot: string | null): string {
|
|
54
|
+
const namingPath = normalizePathForMatching(gitRoot ?? projectPath)
|
|
55
|
+
const parts = namingPath.split('/').filter(Boolean)
|
|
56
|
+
const segmentCount = Math.max(1, dirLength)
|
|
57
|
+
const relevantParts = parts.slice(-segmentCount)
|
|
58
|
+
const joined = relevantParts.length > 0 ? relevantParts.join('_') : basename(projectPath)
|
|
59
|
+
|
|
60
|
+
return sanitizeSessionName(joined)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function resolveProjectSession(
|
|
64
|
+
projectPath: string,
|
|
65
|
+
config: Config,
|
|
66
|
+
options: ResolveProjectSessionOptions = {}
|
|
67
|
+
): Promise<ResolvedProjectSession> {
|
|
68
|
+
const normalizedProjectPath = normalizePathForMatching(projectPath)
|
|
69
|
+
const getGitRootForPath = options.getGitRoot ?? getGitRoot
|
|
70
|
+
const projectProfile = findProjectProfile(normalizedProjectPath, config)
|
|
71
|
+
|
|
72
|
+
if (projectProfile) {
|
|
73
|
+
const gitRoot = await getGitRootForPath(projectPath)
|
|
74
|
+
return {
|
|
75
|
+
sessionName: sanitizeSessionName(projectProfile.sessionName ?? buildSessionName(projectPath, config.dirLength, gitRoot)),
|
|
76
|
+
startupCommand: projectProfile.startupCommand ?? config.defaultSession?.startupCommand,
|
|
77
|
+
previewCommand: projectProfile.previewCommand ?? config.defaultSession?.previewCommand,
|
|
78
|
+
source: 'project',
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const wildcard = findWildcard(normalizedProjectPath, config)
|
|
83
|
+
if (wildcard) {
|
|
84
|
+
const gitRoot = await getGitRootForPath(projectPath)
|
|
85
|
+
return {
|
|
86
|
+
sessionName: sanitizeSessionName(wildcard.sessionName ?? buildSessionName(projectPath, config.dirLength, gitRoot)),
|
|
87
|
+
startupCommand: wildcard.startupCommand ?? config.defaultSession?.startupCommand,
|
|
88
|
+
previewCommand: wildcard.previewCommand ?? config.defaultSession?.previewCommand,
|
|
89
|
+
source: 'wildcard',
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const gitRoot = await getGitRootForPath(projectPath)
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
sessionName: buildSessionName(projectPath, config.dirLength, gitRoot),
|
|
97
|
+
startupCommand: config.defaultSession?.startupCommand,
|
|
98
|
+
previewCommand: config.defaultSession?.previewCommand,
|
|
99
|
+
source: 'default',
|
|
100
|
+
}
|
|
101
|
+
}
|