mux-sesh 1.6.3 → 1.7.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 +90 -59
- package/package.json +7 -5
- package/src/app/commands.ts +120 -0
- package/src/app/controller.ts +397 -0
- package/src/app/controls.ts +121 -0
- package/src/app/core-state.ts +71 -0
- package/src/app/data.ts +90 -0
- package/src/app/derived.ts +77 -0
- package/src/app/effects.ts +392 -0
- package/src/app/handlers.ts +325 -0
- package/src/app/keyboard.ts +161 -0
- package/src/app/modal-keyboard.ts +118 -0
- package/src/app/modal-state.ts +50 -0
- package/src/app/modals-layer.tsx +159 -0
- package/src/app/modals.ts +108 -0
- package/src/app/notifications.ts +21 -0
- package/src/app/opencode.ts +49 -0
- package/src/app/operations.ts +31 -0
- package/src/app/runtime.ts +76 -0
- package/src/app/screen.tsx +217 -0
- package/src/app/state.ts +166 -0
- package/src/app/textarea.ts +16 -0
- package/src/app/view.ts +89 -0
- package/src/app.tsx +7 -1101
- package/src/config/index.ts +36 -42
- package/src/config/listed-sessions.ts +2 -5
- package/src/config/paths.ts +13 -0
- package/src/config/session-rules.ts +10 -11
- package/src/config/store.ts +26 -0
- package/src/handlers/action-helpers.ts +50 -0
- package/src/handlers/actions.ts +34 -65
- package/src/handlers/keyboard/index.ts +5 -0
- package/src/handlers/keyboard/new-session.ts +57 -0
- package/src/handlers/keyboard/normal.ts +201 -0
- package/src/handlers/keyboard/opencode.ts +104 -0
- package/src/handlers/keyboard/search.ts +113 -0
- package/src/handlers/keyboard/shared.ts +116 -0
- package/src/items/order.ts +21 -2
- package/src/opencode/sqlite.ts +21 -6
- package/src/preview/project.ts +41 -15
- package/src/search/index.ts +4 -1
- package/src/settings.ts +294 -297
- package/src/styles/opencode-themes-a.ts +1442 -1
- package/src/styles/opencode-themes-b.ts +1212 -1
- package/src/styles/opencode-tui-colors.ts +1784 -1
- package/src/styles/theme.tsx +2 -1
- package/src/tmux/actions.ts +103 -0
- package/src/tmux/details.ts +123 -0
- package/src/tmux/helpers.ts +35 -0
- package/src/tmux/index.ts +10 -286
- package/src/tmux/list.ts +31 -0
- package/src/tmux/project-discovery.ts +113 -0
- package/src/tmux/project-loader.ts +74 -0
- package/src/tmux/project-zoxide.ts +128 -0
- package/src/tmux/projects.ts +23 -261
- package/src/types/index.ts +0 -1
- package/src/ui/CommandsModal.tsx +87 -22
- package/src/ui/HighlightedText.tsx +1 -5
- package/src/ui/ItemList.tsx +26 -11
- package/src/ui/Modal.tsx +8 -1
- package/src/ui/OpencodeSessionGroup.tsx +20 -9
- package/src/ui/OpencodeStatsPanel.tsx +48 -15
- package/src/ui/RenameModal.tsx +17 -17
- package/src/ui/SearchInput.tsx +1 -20
- package/src/ui/SessionDetailsPanel.tsx +43 -15
- package/src/ui/SessionList.tsx +25 -4
- package/src/ui/SettingEditorModal.tsx +15 -9
- package/src/ui/SettingOptionsModal.tsx +30 -12
- package/src/ui/SettingsModal.tsx +20 -14
- package/src/ui/VersionBadge.tsx +3 -1
- package/src/ui/item-icon.ts +5 -1
- package/src/ui/list-window.ts +5 -1
- package/src/ui/text-columns.ts +17 -0
- package/src/ui/use-textarea-focus.ts +26 -0
- package/src/update/index.ts +10 -2
- package/src/update/installation.ts +6 -2
- package/src/util/ansi.ts +3 -0
- package/src/util/glob.ts +5 -1
- package/src/util/path-display.ts +98 -0
- package/src/components/KeybindHelp.tsx +0 -289
- package/src/handlers/keyboard.ts +0 -654
- package/src/ui/SessionStats.tsx +0 -32
package/src/ui/SessionList.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import { getSessionSection } from '../items/order'
|
|
|
5
5
|
import HighlightedText from './HighlightedText'
|
|
6
6
|
import { formatSectionHeader, getItemIconPresentation } from './item-icon'
|
|
7
7
|
import { getVisibleWindow } from './list-window'
|
|
8
|
+
import { getMutedLabelColumnWidth, getMutedLabelSpacer } from './text-columns'
|
|
8
9
|
|
|
9
10
|
interface Props {
|
|
10
11
|
items: Item[]
|
|
@@ -26,6 +27,7 @@ export default function SessionList({
|
|
|
26
27
|
const theme = useTheme()
|
|
27
28
|
const isSearching = searchQuery.trim().length > 0
|
|
28
29
|
const visibleWindow = getVisibleWindow(items, cursor, maxItems)
|
|
30
|
+
const mutedLabelColumnWidth = getMutedLabelColumnWidth(items)
|
|
29
31
|
|
|
30
32
|
return (
|
|
31
33
|
<>
|
|
@@ -41,11 +43,19 @@ export default function SessionList({
|
|
|
41
43
|
const sectionHeader = formatSectionHeader(theme, currentSection, icons)
|
|
42
44
|
const pendingKill = item.title === pendingKillSessionName
|
|
43
45
|
const selected = absoluteIndex === cursor
|
|
46
|
+
const mutedLabelSpacer =
|
|
47
|
+
item.isSession && item.desc ? getMutedLabelSpacer(item.title, mutedLabelColumnWidth) : ''
|
|
44
48
|
|
|
45
49
|
return (
|
|
46
50
|
<box key={i} style={{ flexDirection: 'column' }}>
|
|
47
51
|
{showSectionHeader && (
|
|
48
|
-
<text
|
|
52
|
+
<text
|
|
53
|
+
style={{
|
|
54
|
+
fg: theme.textSubtle,
|
|
55
|
+
marginTop: absoluteIndex === 0 ? 0 : 1,
|
|
56
|
+
marginBottom: 1,
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
49
59
|
<span style={{ fg: sectionHeader.color }}>{sectionHeader.text}</span>
|
|
50
60
|
</text>
|
|
51
61
|
)}
|
|
@@ -54,20 +64,31 @@ export default function SessionList({
|
|
|
54
64
|
style={{
|
|
55
65
|
flexDirection: 'row',
|
|
56
66
|
justifyContent: 'space-between',
|
|
57
|
-
backgroundColor: pendingKill
|
|
67
|
+
backgroundColor: pendingKill
|
|
68
|
+
? theme.dangerSurface
|
|
69
|
+
: selected
|
|
70
|
+
? theme.surfaceAlt
|
|
71
|
+
: 'transparent',
|
|
58
72
|
paddingLeft: 1,
|
|
59
73
|
paddingRight: 1,
|
|
60
74
|
}}
|
|
61
75
|
>
|
|
62
76
|
<text>
|
|
63
|
-
<span style={{ fg: selected ? theme.primary : theme.textSubtle }}>
|
|
64
|
-
|
|
77
|
+
<span style={{ fg: selected ? theme.primary : theme.textSubtle }}>
|
|
78
|
+
{selected ? '› ' : ' '}
|
|
79
|
+
</span>
|
|
80
|
+
<span style={{ fg: item.isAttached ? theme.active : theme.inactive }}>
|
|
81
|
+
{item.isAttached ? '●' : '○'}
|
|
82
|
+
</span>
|
|
65
83
|
<span style={{ fg: icon.color }}>{icon.glyph ? ` ${icon.glyph}` : ''}</span>{' '}
|
|
66
84
|
{isSearching && matchIndices && matchIndices.length > 0 ? (
|
|
67
85
|
<HighlightedText text={item.title} matchIndices={matchIndices} />
|
|
68
86
|
) : (
|
|
69
87
|
<span style={{ fg: theme.text }}>{item.title}</span>
|
|
70
88
|
)}
|
|
89
|
+
{item.isSession && item.desc ? (
|
|
90
|
+
<span style={{ fg: theme.textSubtle }}>{`${mutedLabelSpacer}${item.desc}`}</span>
|
|
91
|
+
) : null}
|
|
71
92
|
</text>
|
|
72
93
|
|
|
73
94
|
<text style={{ fg: pendingKill ? theme.danger : theme.textSubtle }}>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TextareaRenderable } from '@opentui/core'
|
|
2
|
-
import { useEffect } from 'react'
|
|
3
2
|
import { useTheme } from '../styles/theme'
|
|
4
3
|
import Modal from './Modal'
|
|
4
|
+
import { useTextareaFocus } from './use-textarea-focus'
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
title: string
|
|
@@ -25,15 +25,16 @@ export default function SettingEditorModal({
|
|
|
25
25
|
onContentChange,
|
|
26
26
|
}: Props) {
|
|
27
27
|
const theme = useTheme()
|
|
28
|
-
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
queueMicrotask(() => {
|
|
31
|
-
textareaRef.current?.focus()
|
|
32
|
-
})
|
|
33
|
-
}, [textareaRef])
|
|
28
|
+
useTextareaFocus(textareaRef, [])
|
|
34
29
|
|
|
35
30
|
return (
|
|
36
|
-
<Modal
|
|
31
|
+
<Modal
|
|
32
|
+
title={title}
|
|
33
|
+
description={description}
|
|
34
|
+
footer="Enter apply"
|
|
35
|
+
columns={columns}
|
|
36
|
+
preferredWidth={88}
|
|
37
|
+
>
|
|
37
38
|
{error && <text style={{ fg: theme.danger, marginBottom: 1 }}>{error}</text>}
|
|
38
39
|
|
|
39
40
|
<box
|
|
@@ -42,7 +43,12 @@ export default function SettingEditorModal({
|
|
|
42
43
|
height: Math.max(6, rows - 16),
|
|
43
44
|
}}
|
|
44
45
|
>
|
|
45
|
-
<textarea
|
|
46
|
+
<textarea
|
|
47
|
+
ref={textareaRef}
|
|
48
|
+
initialValue={value}
|
|
49
|
+
onContentChange={onContentChange}
|
|
50
|
+
focused
|
|
51
|
+
/>
|
|
46
52
|
</box>
|
|
47
53
|
</Modal>
|
|
48
54
|
)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { TextareaRenderable } from '@opentui/core'
|
|
2
|
-
import { useEffect } from 'react'
|
|
3
2
|
import { useTheme } from '../styles/theme'
|
|
4
3
|
import type { SettingsOption } from '../settings'
|
|
5
4
|
import Modal from './Modal'
|
|
5
|
+
import { useTextareaFocus } from './use-textarea-focus'
|
|
6
6
|
|
|
7
7
|
interface Props {
|
|
8
8
|
title: string
|
|
@@ -27,17 +27,31 @@ export default function SettingOptionsModal({
|
|
|
27
27
|
}: Props) {
|
|
28
28
|
const theme = useTheme()
|
|
29
29
|
const selected = options[cursor]
|
|
30
|
-
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
queueMicrotask(() => {
|
|
33
|
-
textareaRef.current?.focus()
|
|
34
|
-
})
|
|
35
|
-
}, [textareaRef])
|
|
30
|
+
useTextareaFocus(textareaRef, [])
|
|
36
31
|
|
|
37
32
|
return (
|
|
38
|
-
<Modal
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
<Modal
|
|
34
|
+
title={title}
|
|
35
|
+
description={description}
|
|
36
|
+
footer="↑/↓ navigate enter apply esc back"
|
|
37
|
+
columns={columns}
|
|
38
|
+
preferredWidth={68}
|
|
39
|
+
>
|
|
40
|
+
<box
|
|
41
|
+
style={{
|
|
42
|
+
backgroundColor: theme.surfaceAlt,
|
|
43
|
+
paddingLeft: 1,
|
|
44
|
+
paddingRight: 1,
|
|
45
|
+
marginBottom: 1,
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
<textarea
|
|
49
|
+
ref={textareaRef}
|
|
50
|
+
initialValue={searchQuery}
|
|
51
|
+
onContentChange={onContentChange}
|
|
52
|
+
focused
|
|
53
|
+
placeholder="Filter options"
|
|
54
|
+
/>
|
|
41
55
|
</box>
|
|
42
56
|
|
|
43
57
|
<box style={{ flexDirection: 'column' }}>
|
|
@@ -58,8 +72,12 @@ export default function SettingOptionsModal({
|
|
|
58
72
|
paddingRight: 1,
|
|
59
73
|
}}
|
|
60
74
|
>
|
|
61
|
-
<text style={{ fg: active ? theme.selectionText : theme.text }}>
|
|
62
|
-
|
|
75
|
+
<text style={{ fg: active ? theme.selectionText : theme.text }}>
|
|
76
|
+
{option.label}
|
|
77
|
+
</text>
|
|
78
|
+
<text style={{ fg: active ? theme.selectionText : theme.textMuted }}>
|
|
79
|
+
{option.value}
|
|
80
|
+
</text>
|
|
63
81
|
</box>
|
|
64
82
|
)
|
|
65
83
|
})
|
package/src/ui/SettingsModal.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { TextareaRenderable } from '@opentui/core'
|
|
2
|
-
import { useEffect } from 'react'
|
|
3
2
|
import { useTheme } from '../styles/theme'
|
|
4
3
|
import type { SettingsEntry } from '../settings'
|
|
5
4
|
import Modal from './Modal'
|
|
5
|
+
import { useTextareaFocus } from './use-textarea-focus'
|
|
6
6
|
|
|
7
7
|
interface Props {
|
|
8
8
|
configPath: string
|
|
@@ -29,33 +29,37 @@ export default function SettingsModal({
|
|
|
29
29
|
}: Props) {
|
|
30
30
|
const theme = useTheme()
|
|
31
31
|
const selected = entries[cursor]
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
queueMicrotask(() => {
|
|
35
|
-
textareaRef.current?.focus()
|
|
36
|
-
})
|
|
37
|
-
}, [textareaRef])
|
|
32
|
+
useTextareaFocus(textareaRef, [])
|
|
38
33
|
|
|
39
34
|
return (
|
|
40
35
|
<Modal
|
|
41
|
-
title=
|
|
42
|
-
description=
|
|
43
|
-
footer=
|
|
36
|
+
title="Settings"
|
|
37
|
+
description="Search for a setting, then open its option or editor screen"
|
|
38
|
+
footer="↑/↓ navigate enter open esc close"
|
|
44
39
|
columns={columns}
|
|
45
40
|
preferredWidth={74}
|
|
46
41
|
>
|
|
47
42
|
<box style={{ flexDirection: 'column', marginBottom: 1 }}>
|
|
48
43
|
<text style={{ fg: theme.textMuted }}>Path: {configPath}</text>
|
|
49
|
-
<text style={{ fg: theme.textMuted }}>
|
|
44
|
+
<text style={{ fg: theme.textMuted }}>
|
|
45
|
+
{themeName} ({colorMode})
|
|
46
|
+
</text>
|
|
50
47
|
</box>
|
|
51
48
|
|
|
52
|
-
<box
|
|
49
|
+
<box
|
|
50
|
+
style={{
|
|
51
|
+
backgroundColor: theme.surfaceAlt,
|
|
52
|
+
paddingLeft: 1,
|
|
53
|
+
paddingRight: 1,
|
|
54
|
+
marginBottom: 1,
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
53
57
|
<textarea
|
|
54
58
|
ref={textareaRef}
|
|
55
59
|
initialValue={searchQuery}
|
|
56
60
|
onContentChange={onContentChange}
|
|
57
61
|
focused
|
|
58
|
-
placeholder=
|
|
62
|
+
placeholder="Search settings"
|
|
59
63
|
/>
|
|
60
64
|
</box>
|
|
61
65
|
|
|
@@ -78,7 +82,9 @@ export default function SettingsModal({
|
|
|
78
82
|
}}
|
|
79
83
|
>
|
|
80
84
|
<text style={{ fg: active ? theme.selectionText : theme.text }}>{entry.label}</text>
|
|
81
|
-
<text style={{ fg: active ? theme.selectionText : theme.textMuted }}>
|
|
85
|
+
<text style={{ fg: active ? theme.selectionText : theme.textMuted }}>
|
|
86
|
+
{entry.value}
|
|
87
|
+
</text>
|
|
82
88
|
</box>
|
|
83
89
|
)
|
|
84
90
|
})
|
package/src/ui/VersionBadge.tsx
CHANGED
|
@@ -24,7 +24,9 @@ export default function VersionBadge({ currentVersion, updatedVersion }: Version
|
|
|
24
24
|
right: 1,
|
|
25
25
|
}}
|
|
26
26
|
>
|
|
27
|
-
<text style={{ fg: theme.textSubtle }}>
|
|
27
|
+
<text style={{ fg: theme.textSubtle }}>
|
|
28
|
+
{formatVersionBadge(currentVersion, updatedVersion)}
|
|
29
|
+
</text>
|
|
28
30
|
</box>
|
|
29
31
|
)
|
|
30
32
|
}
|
package/src/ui/item-icon.ts
CHANGED
|
@@ -14,7 +14,11 @@ function getIconConfig(icons?: IconConfig): IconConfig {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function getItemIconPresentation(
|
|
17
|
+
export function getItemIconPresentation(
|
|
18
|
+
theme: ThemeColors,
|
|
19
|
+
item: Item,
|
|
20
|
+
icons?: IconConfig
|
|
21
|
+
): ItemIconPresentation {
|
|
18
22
|
const resolvedIcons = getIconConfig(icons)
|
|
19
23
|
|
|
20
24
|
if (item.itemKind === 'configured') {
|
package/src/ui/list-window.ts
CHANGED
|
@@ -3,7 +3,11 @@ export interface VisibleWindow<T> {
|
|
|
3
3
|
startIndex: number
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
export function getVisibleWindow<T>(
|
|
6
|
+
export function getVisibleWindow<T>(
|
|
7
|
+
items: T[],
|
|
8
|
+
cursor: number,
|
|
9
|
+
maxItems: number
|
|
10
|
+
): VisibleWindow<T> {
|
|
7
11
|
if (items.length === 0) {
|
|
8
12
|
return {
|
|
9
13
|
items: [],
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Item } from '../types'
|
|
2
|
+
|
|
3
|
+
const MIN_COLUMN_GAP = 2
|
|
4
|
+
|
|
5
|
+
export function getMutedLabelColumnWidth(items: Item[]): number {
|
|
6
|
+
return items.reduce((maxWidth, item) => {
|
|
7
|
+
if (!item.isSession || !item.desc) {
|
|
8
|
+
return maxWidth
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return Math.max(maxWidth, item.title.length)
|
|
12
|
+
}, 0)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getMutedLabelSpacer(title: string, columnWidth: number): string {
|
|
16
|
+
return ' '.repeat(Math.max(MIN_COLUMN_GAP, columnWidth - title.length + MIN_COLUMN_GAP))
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TextareaRenderable } from '@opentui/core'
|
|
2
|
+
import { useEffect } from 'react'
|
|
3
|
+
|
|
4
|
+
interface Options {
|
|
5
|
+
gotoLineEnd?: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function useTextareaFocus(
|
|
9
|
+
textareaRef: { current: TextareaRenderable | null },
|
|
10
|
+
dependencies: readonly unknown[],
|
|
11
|
+
options: Options = {}
|
|
12
|
+
) {
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
queueMicrotask(() => {
|
|
15
|
+
const textarea = textareaRef.current
|
|
16
|
+
if (!textarea) {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
textarea.focus()
|
|
21
|
+
if (options.gotoLineEnd) {
|
|
22
|
+
textarea.gotoLineEnd()
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
}, [options.gotoLineEnd, textareaRef, ...dependencies])
|
|
26
|
+
}
|
package/src/update/index.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { Config } from '../types'
|
|
2
2
|
import { CURRENT_VERSION, getLatestVersion, isNewerVersion } from './version'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
canAutoUpdate,
|
|
5
|
+
detectInstallMethod,
|
|
6
|
+
getInstalledVersion,
|
|
7
|
+
performUpgrade,
|
|
8
|
+
} from './installation'
|
|
4
9
|
import { updateEvents } from './events'
|
|
5
10
|
|
|
6
11
|
interface UpdateDependencies {
|
|
@@ -28,7 +33,10 @@ function truthy(key: string): boolean {
|
|
|
28
33
|
return value === 'true' || value === '1'
|
|
29
34
|
}
|
|
30
35
|
|
|
31
|
-
export async function checkAndUpdate(
|
|
36
|
+
export async function checkAndUpdate(
|
|
37
|
+
config: Config,
|
|
38
|
+
dependencies: Partial<UpdateDependencies> = {}
|
|
39
|
+
): Promise<void> {
|
|
32
40
|
const resolvedDependencies = {
|
|
33
41
|
...defaultDependencies,
|
|
34
42
|
...dependencies,
|
|
@@ -71,7 +71,9 @@ async function detectInstallMethodFromPath(runtimePath: string): Promise<Install
|
|
|
71
71
|
return (await findPackageRoot(normalizedPath)) ? 'source' : 'unknown'
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export async function detectInstallMethod(
|
|
74
|
+
export async function detectInstallMethod(
|
|
75
|
+
runtimePath = getDefaultRuntimePath()
|
|
76
|
+
): Promise<InstallMethod> {
|
|
75
77
|
const activeMethod = await detectInstallMethodFromPath(runtimePath)
|
|
76
78
|
if (activeMethod !== 'unknown') {
|
|
77
79
|
return activeMethod
|
|
@@ -111,7 +113,9 @@ export function canAutoUpdate(method: InstallMethod): boolean {
|
|
|
111
113
|
return method === 'npm' || method === 'bun'
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
export async function getInstalledVersion(
|
|
116
|
+
export async function getInstalledVersion(
|
|
117
|
+
runtimePath = getDefaultRuntimePath()
|
|
118
|
+
): Promise<string | null> {
|
|
115
119
|
const packageRoot = await findPackageRoot(runtimePath)
|
|
116
120
|
|
|
117
121
|
if (!packageRoot) {
|
package/src/util/ansi.ts
ADDED
package/src/util/glob.ts
CHANGED
|
@@ -42,6 +42,10 @@ export function globToRegExp(pattern: string, options: MatchGlobOptions = {}): R
|
|
|
42
42
|
return new RegExp(regex)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
export function matchesGlob(
|
|
45
|
+
export function matchesGlob(
|
|
46
|
+
value: string,
|
|
47
|
+
pattern: string,
|
|
48
|
+
options: MatchGlobOptions = {}
|
|
49
|
+
): boolean {
|
|
46
50
|
return globToRegExp(pattern, options).test(value)
|
|
47
51
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { basename, dirname } from 'path'
|
|
2
|
+
|
|
3
|
+
function toHomeRelativePath(path: string): string {
|
|
4
|
+
const homeDir = process.env.HOME || ''
|
|
5
|
+
|
|
6
|
+
if (!path) {
|
|
7
|
+
return ''
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (homeDir && path === homeDir) {
|
|
11
|
+
return '~'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (homeDir && path.startsWith(`${homeDir}/`)) {
|
|
15
|
+
return `~${path.slice(homeDir.length)}`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return path
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getWorktreeProjectName(path: string): string | null {
|
|
22
|
+
if (!path) {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const parentPath = dirname(path)
|
|
27
|
+
|
|
28
|
+
if (basename(parentPath) !== '.worktrees') {
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const projectName = basename(dirname(parentPath))
|
|
33
|
+
return projectName && projectName !== '.' && projectName !== '/' ? projectName : null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getPathGroupLabel(path: string): string {
|
|
37
|
+
if (!path) {
|
|
38
|
+
return ''
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const parentPath = dirname(path)
|
|
42
|
+
if ((process.env.HOME || '') && parentPath === (process.env.HOME || '')) {
|
|
43
|
+
return '~'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const worktreeProject = getWorktreeProjectName(path)
|
|
47
|
+
if (worktreeProject) {
|
|
48
|
+
return worktreeProject
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const parentName = basename(parentPath)
|
|
52
|
+
|
|
53
|
+
if (!parentName || parentName === '.' || parentName === '/') {
|
|
54
|
+
return ''
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return parentName
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getPathContextLabel(path: string): string {
|
|
61
|
+
if (!path) {
|
|
62
|
+
return ''
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const parentPath = dirname(path)
|
|
66
|
+
|
|
67
|
+
if (!parentPath || parentPath === '.' || parentPath === '/') {
|
|
68
|
+
return parentPath === '/' ? '/' : ''
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const worktreeProject = getWorktreeProjectName(path)
|
|
72
|
+
if (worktreeProject) {
|
|
73
|
+
return `${toHomeRelativePath(dirname(parentPath))} [worktree]`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return toHomeRelativePath(parentPath)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function getLiveSessionGroupLabel(path: string): string {
|
|
80
|
+
const worktreeProject = getWorktreeProjectName(path)
|
|
81
|
+
|
|
82
|
+
if (worktreeProject) {
|
|
83
|
+
return `${worktreeProject} [worktree]`
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return getPathGroupLabel(path)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function getLiveSessionSortKey(path: string, title: string): string {
|
|
90
|
+
const worktreeProject = getWorktreeProjectName(path)
|
|
91
|
+
|
|
92
|
+
if (worktreeProject) {
|
|
93
|
+
return worktreeProject
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const baseName = basename(path)
|
|
97
|
+
return baseName && baseName !== '.' && baseName !== '/' ? baseName : title
|
|
98
|
+
}
|