@jhorst11/wt 2.0.2 → 2.2.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.
@@ -0,0 +1,387 @@
1
+ import { simpleGit } from 'simple-git';
2
+ import { join, basename } from 'path';
3
+ import { existsSync, mkdirSync, readdirSync, statSync } from 'fs';
4
+ import { resolveConfig } from './config.js';
5
+ export async function getGit(cwd = process.cwd()) {
6
+ return simpleGit(cwd);
7
+ }
8
+ export async function isGitRepo(cwd = process.cwd()) {
9
+ try {
10
+ const git = await getGit(cwd);
11
+ await git.revparse(['--git-dir']);
12
+ return true;
13
+ }
14
+ catch {
15
+ return false;
16
+ }
17
+ }
18
+ export async function getRepoRoot(cwd = process.cwd()) {
19
+ try {
20
+ const git = await getGit(cwd);
21
+ const root = await git.revparse(['--show-toplevel']);
22
+ return root.trim();
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ }
28
+ export async function getCurrentBranch(cwd = process.cwd()) {
29
+ try {
30
+ const git = await getGit(cwd);
31
+ const branch = await git.revparse(['--abbrev-ref', 'HEAD']);
32
+ return branch.trim();
33
+ }
34
+ catch {
35
+ return null;
36
+ }
37
+ }
38
+ export async function getLocalBranches(cwd = process.cwd()) {
39
+ try {
40
+ const git = await getGit(cwd);
41
+ const result = await git.branchLocal();
42
+ return result.all.map((name) => ({
43
+ name,
44
+ isCurrent: name === result.current,
45
+ }));
46
+ }
47
+ catch {
48
+ return [];
49
+ }
50
+ }
51
+ export async function getRemoteBranches(cwd = process.cwd()) {
52
+ try {
53
+ const git = await getGit(cwd);
54
+ // Fetch latest from remote first
55
+ await git.fetch(['--all', '--prune']).catch(() => { });
56
+ const result = await git.branch(['-r']);
57
+ return result.all
58
+ .filter((name) => !name.includes('HEAD'))
59
+ .map((name) => ({
60
+ name: name.replace(/^origin\//, ''),
61
+ fullName: name,
62
+ isRemote: true,
63
+ }));
64
+ }
65
+ catch {
66
+ return [];
67
+ }
68
+ }
69
+ export async function getAllBranches(cwd = process.cwd()) {
70
+ const [local, remote] = await Promise.all([
71
+ getLocalBranches(cwd),
72
+ getRemoteBranches(cwd),
73
+ ]);
74
+ // Merge and dedupe, preferring local branches
75
+ const localNames = new Set(local.map((b) => b.name));
76
+ const uniqueRemote = remote.filter((b) => !localNames.has(b.name));
77
+ return {
78
+ local,
79
+ remote: uniqueRemote,
80
+ all: [...local.map((b) => ({ ...b, type: 'local' })), ...uniqueRemote.map((b) => ({ ...b, type: 'remote' }))],
81
+ };
82
+ }
83
+ export function getWorktreesBase(repoRoot, config) {
84
+ const projectsDir = (config.projectsDir || '').replace(/\/$/, '');
85
+ let repoRel;
86
+ if (repoRoot.startsWith(projectsDir + '/')) {
87
+ repoRel = repoRoot.slice(projectsDir.length + 1);
88
+ }
89
+ else {
90
+ repoRel = basename(repoRoot);
91
+ }
92
+ return join(config.worktreesDir || '', repoRel);
93
+ }
94
+ export async function getWorktrees(cwd = process.cwd()) {
95
+ try {
96
+ const git = await getGit(cwd);
97
+ const result = await git.raw(['worktree', 'list', '--porcelain']);
98
+ const worktrees = [];
99
+ let current = {};
100
+ for (const line of result.split('\n')) {
101
+ if (line.startsWith('worktree ')) {
102
+ if (current.path)
103
+ worktrees.push(current);
104
+ current = { path: line.slice(9) };
105
+ }
106
+ else if (line.startsWith('branch ')) {
107
+ current.branch = line.slice(7).replace('refs/heads/', '');
108
+ }
109
+ else if (line === 'bare') {
110
+ current.bare = true;
111
+ }
112
+ else if (line === 'detached') {
113
+ current.detached = true;
114
+ }
115
+ }
116
+ if (current.path)
117
+ worktrees.push(current);
118
+ // Add name (last part of path) and identify main vs worktrees
119
+ return worktrees.map((wt, index) => ({
120
+ name: basename(wt.path),
121
+ path: wt.path,
122
+ branch: wt.branch || 'unknown',
123
+ isMain: index === 0,
124
+ bare: wt.bare,
125
+ detached: wt.detached,
126
+ }));
127
+ }
128
+ catch {
129
+ return [];
130
+ }
131
+ }
132
+ export async function getWorktreesInBase(repoRoot, config) {
133
+ const base = getWorktreesBase(repoRoot, config);
134
+ if (!existsSync(base))
135
+ return [];
136
+ try {
137
+ const entries = readdirSync(base);
138
+ const worktrees = [];
139
+ for (const entry of entries) {
140
+ const entryPath = join(base, entry);
141
+ if (statSync(entryPath).isDirectory()) {
142
+ // Check if it's a valid git worktree
143
+ const gitFile = join(entryPath, '.git');
144
+ if (existsSync(gitFile)) {
145
+ const branch = await getCurrentBranch(entryPath);
146
+ worktrees.push({
147
+ name: entry,
148
+ path: entryPath,
149
+ branch: branch || 'unknown',
150
+ });
151
+ }
152
+ }
153
+ }
154
+ return worktrees;
155
+ }
156
+ catch {
157
+ return [];
158
+ }
159
+ }
160
+ export async function getMainRepoPath(cwd = process.cwd()) {
161
+ try {
162
+ const git = await getGit(cwd);
163
+ const result = await git.raw(['worktree', 'list', '--porcelain']);
164
+ const firstLine = result.split('\n').find((l) => l.startsWith('worktree '));
165
+ return firstLine ? firstLine.slice(9) : null;
166
+ }
167
+ catch {
168
+ return null;
169
+ }
170
+ }
171
+ export function buildBranchName(leaf, config) {
172
+ const cleanLeaf = leaf.replace(/^\//, '').replace(/ /g, '-');
173
+ const prefix = config.branchPrefix || '';
174
+ if (prefix) {
175
+ return `${prefix.replace(/\/$/, '')}/${cleanLeaf}`;
176
+ }
177
+ return cleanLeaf;
178
+ }
179
+ export async function branchExistsLocal(branchName, cwd = process.cwd()) {
180
+ try {
181
+ const git = await getGit(cwd);
182
+ // Do not use --quiet: simple-git swallows non-zero exit codes when output is
183
+ // empty, so `--quiet` (which suppresses output) causes the try-block to
184
+ // succeed even when the ref does not exist. Without --quiet the command
185
+ // prints the SHA on success (keeping the try path) and writes to stderr on
186
+ // failure (causing simple-git to throw into the catch path).
187
+ const result = await git.raw(['show-ref', '--verify', `refs/heads/${branchName}`]);
188
+ return result.trim().length > 0;
189
+ }
190
+ catch {
191
+ return false;
192
+ }
193
+ }
194
+ export async function branchExistsRemote(branchName, cwd = process.cwd()) {
195
+ try {
196
+ const git = await getGit(cwd);
197
+ const result = await git.raw(['ls-remote', '--exit-code', '--heads', 'origin', branchName]);
198
+ return result.length > 0;
199
+ }
200
+ catch {
201
+ return false;
202
+ }
203
+ }
204
+ export async function ensureBranch(branchName, baseBranch = null, cwd = process.cwd()) {
205
+ const git = await getGit(cwd);
206
+ // Resolve detached HEAD to the actual commit SHA so it's usable as a base
207
+ if (baseBranch === 'HEAD') {
208
+ try {
209
+ baseBranch = (await git.revparse(['HEAD'])).trim();
210
+ }
211
+ catch {
212
+ throw new Error('HEAD does not point to a valid commit. Is this a new repository with no commits?');
213
+ }
214
+ }
215
+ // If baseBranch is a remote ref, fetch it first to ensure it's up to date
216
+ if (baseBranch && baseBranch.startsWith('origin/')) {
217
+ const remoteBranchName = baseBranch.replace('origin/', '');
218
+ try {
219
+ await git.fetch(['origin', `${remoteBranchName}:refs/remotes/origin/${remoteBranchName}`]);
220
+ }
221
+ catch {
222
+ // Fetch failed - verify the remote ref still exists locally from a previous fetch
223
+ try {
224
+ await git.revparse(['--verify', baseBranch]);
225
+ }
226
+ catch {
227
+ throw new Error(`Failed to fetch remote branch '${remoteBranchName}' and no local copy exists. The remote branch may have been deleted.`);
228
+ }
229
+ }
230
+ }
231
+ // If baseBranch is specified, verify it resolves to a valid ref
232
+ if (baseBranch) {
233
+ try {
234
+ await git.revparse(['--verify', baseBranch]);
235
+ }
236
+ catch {
237
+ throw new Error(`Base branch '${baseBranch}' does not exist or is not a valid reference.`);
238
+ }
239
+ }
240
+ // Check if branch exists locally
241
+ if (await branchExistsLocal(branchName, cwd)) {
242
+ // If we have a remote baseBranch, update local branch to match it
243
+ if (baseBranch && baseBranch.startsWith('origin/')) {
244
+ try {
245
+ const localSha = (await git.revparse([branchName])).trim();
246
+ const remoteSha = (await git.revparse([baseBranch])).trim();
247
+ if (localSha !== remoteSha) {
248
+ await git.raw(['branch', '-f', branchName, baseBranch]);
249
+ return { created: false, source: 'updated-from-remote' };
250
+ }
251
+ }
252
+ catch {
253
+ // If we can't compare, fall through to use local as-is
254
+ }
255
+ }
256
+ return { created: false, source: 'local' };
257
+ }
258
+ // Check if branch exists on remote (with same name as branchName)
259
+ if (await branchExistsRemote(branchName, cwd)) {
260
+ await git.fetch(['origin', `${branchName}:${branchName}`]);
261
+ return { created: false, source: 'remote' };
262
+ }
263
+ // Create new branch from base
264
+ if (baseBranch) {
265
+ await git.raw(['branch', branchName, baseBranch]);
266
+ }
267
+ else {
268
+ await git.raw(['branch', branchName]);
269
+ }
270
+ return { created: true, source: 'new' };
271
+ }
272
+ export async function createWorktree(name, branchName, baseBranch = null, cwd = process.cwd()) {
273
+ const git = await getGit(cwd);
274
+ const repoRoot = await getRepoRoot(cwd);
275
+ if (!repoRoot) {
276
+ return { success: false, error: 'Not in a git repository' };
277
+ }
278
+ const config = resolveConfig(cwd, repoRoot);
279
+ const worktreesBase = getWorktreesBase(repoRoot, config);
280
+ // Prune stale worktree references before creating a new one
281
+ await pruneWorktrees(cwd);
282
+ // Ensure worktrees directory exists
283
+ if (!existsSync(worktreesBase)) {
284
+ mkdirSync(worktreesBase, { recursive: true });
285
+ }
286
+ const worktreePath = join(worktreesBase, name);
287
+ // Check if worktree already exists
288
+ if (existsSync(worktreePath)) {
289
+ return { success: false, error: 'Worktree directory already exists', path: worktreePath };
290
+ }
291
+ // Fetch all remotes
292
+ await git.fetch(['--all', '--prune']).catch(() => { });
293
+ // Ensure branch exists (or determine if we need to create it)
294
+ const branchResult = await ensureBranch(branchName, baseBranch, cwd);
295
+ // Create worktree — ensureBranch guarantees the branch already exists, so we
296
+ // just attach the worktree to it.
297
+ await git.raw(['worktree', 'add', worktreePath, branchName]);
298
+ return {
299
+ success: true,
300
+ path: worktreePath,
301
+ branch: branchName,
302
+ branchCreated: branchResult.created,
303
+ branchSource: branchResult.source,
304
+ };
305
+ }
306
+ export async function removeWorktree(path, force = false, cwd = process.cwd()) {
307
+ const git = await getGit(cwd);
308
+ // Prune stale worktree references before removing
309
+ await pruneWorktrees(cwd);
310
+ const args = ['worktree', 'remove'];
311
+ if (force)
312
+ args.push('--force');
313
+ args.push(path);
314
+ await git.raw(args);
315
+ return { success: true };
316
+ }
317
+ export async function pruneWorktrees(cwd = process.cwd()) {
318
+ const git = await getGit(cwd);
319
+ await git.raw(['worktree', 'prune']);
320
+ return { success: true };
321
+ }
322
+ export function isValidBranchName(name) {
323
+ // Basic validation - git allows most characters but not some special ones
324
+ if (!name || name.length === 0)
325
+ return false;
326
+ if (name.startsWith('-') || name.startsWith('.'))
327
+ return false;
328
+ if (name.endsWith('/') || name.endsWith('.'))
329
+ return false;
330
+ if (name.includes('..') || name.includes('//'))
331
+ return false;
332
+ if (/[\s~^:?*\[\]\\]/.test(name))
333
+ return false;
334
+ return true;
335
+ }
336
+ export async function mergeBranch(sourceBranch, targetBranch = null, cwd = process.cwd()) {
337
+ const git = await getGit(cwd);
338
+ // If target specified, checkout to it first
339
+ if (targetBranch) {
340
+ await git.checkout(targetBranch);
341
+ }
342
+ // Merge the source branch
343
+ const result = await git.merge([sourceBranch, '--no-edit']);
344
+ return {
345
+ success: true,
346
+ merged: sourceBranch,
347
+ into: targetBranch || await getCurrentBranch(cwd),
348
+ result,
349
+ };
350
+ }
351
+ export async function getMainBranch(cwd = process.cwd()) {
352
+ const git = await getGit(cwd);
353
+ // Try common main branch names
354
+ const candidates = ['main', 'master', 'develop'];
355
+ const branches = await getLocalBranches(cwd);
356
+ const branchNames = branches.map(b => b.name);
357
+ for (const candidate of candidates) {
358
+ if (branchNames.includes(candidate)) {
359
+ return candidate;
360
+ }
361
+ }
362
+ // Fall back to first branch
363
+ return branchNames[0] || 'main';
364
+ }
365
+ export async function hasUncommittedChanges(cwd = process.cwd()) {
366
+ const git = await getGit(cwd);
367
+ const status = await git.status();
368
+ return !status.isClean();
369
+ }
370
+ export async function deleteBranch(branchName, force = false, cwd = process.cwd()) {
371
+ const git = await getGit(cwd);
372
+ const flag = force ? '-D' : '-d';
373
+ await git.branch([flag, branchName]);
374
+ return { success: true };
375
+ }
376
+ /**
377
+ * Get information about the current worktree if user is inside one.
378
+ * Returns the worktree object with name, path, and branch if inside a worktree.
379
+ * Returns null if in main repository or error occurs.
380
+ */
381
+ export async function getCurrentWorktreeInfo(repoRoot, config) {
382
+ const currentPath = process.cwd();
383
+ const worktrees = await getWorktreesInBase(repoRoot, config);
384
+ const currentWt = worktrees.find(wt => currentPath === wt.path || currentPath.startsWith(wt.path + '/'));
385
+ return currentWt || null;
386
+ }
387
+ //# sourceMappingURL=git.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,MAAc,OAAO,CAAC,GAAG,EAAE;IACtD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAc,OAAO,CAAC,GAAG,EAAE;IACzD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;QAC9B,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAc,OAAO,CAAC,GAAG,EAAE;IAC3D,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;QAC9B,MAAM,IAAI,GAAG,MAA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GAAG,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;IAC9B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACjC,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;IACrC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,QAAgB,EAAE,MAAc;IAC3E,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAClC,MAAM,SAAS,GAAG,MAAM,kBAAkB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAE7D,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CACpC,WAAW,KAAK,EAAE,CAAC,IAAI,IAAI,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC,CACjE,CAAC;IAEF,OAAO,SAAS,IAAI,IAAI,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ShellConfig, WrapperStatus } from './types.js';
2
+ export declare function detectShell(): 'zsh' | 'bash' | 'fish' | 'unknown';
3
+ export declare function getShellConfig(): ShellConfig | null;
4
+ export declare function isWrapperInstalled(): boolean;
5
+ export declare function checkWrapperInRcFile(): WrapperStatus;
6
+ export declare function setupCommand(): Promise<void>;
7
+ export declare function showCdHint(path: string): void;
8
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/setup.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG7D,wBAAgB,WAAW,IAAI,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAWjE;AAED,wBAAgB,cAAc,IAAI,WAAW,GAAG,IAAI,CA8DnD;AAED,wBAAgB,kBAAkB,IAAI,OAAO,CAI5C;AAED,wBAAgB,oBAAoB,IAAI,aAAa,CAiBpD;AAED,wBAAsB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CA+ElD;AAsCD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CA6B7C"}
@@ -0,0 +1,245 @@
1
+ import { select } from '@inquirer/prompts';
2
+ import { ExitPromptError } from '@inquirer/core';
3
+ import { homedir } from 'os';
4
+ import { existsSync, readFileSync, appendFileSync, writeFileSync } from 'fs';
5
+ import { join } from 'path';
6
+ import { showMiniLogo, success, error, warning, info, heading, spacer, colors, icons, divider, } from './ui.js';
7
+ // Shell detection
8
+ export function detectShell() {
9
+ const shell = process.env.SHELL || '';
10
+ if (shell.includes('zsh'))
11
+ return 'zsh';
12
+ if (shell.includes('bash'))
13
+ return 'bash';
14
+ if (shell.includes('fish'))
15
+ return 'fish';
16
+ if (process.env.FISH_VERSION)
17
+ return 'fish';
18
+ if (process.env.ZSH_VERSION)
19
+ return 'zsh';
20
+ if (process.env.BASH_VERSION)
21
+ return 'bash';
22
+ return 'unknown';
23
+ }
24
+ export function getShellConfig() {
25
+ const shell = detectShell();
26
+ const home = homedir();
27
+ const configs = {
28
+ zsh: {
29
+ name: 'Zsh',
30
+ rcFile: join(home, '.zshrc'),
31
+ wrapper: `
32
+ # wt-cli: Git worktree manager shell integration
33
+ wt() {
34
+ local wt_cd_file="/tmp/wt_cd_$$"
35
+ rm -f "$wt_cd_file"
36
+ WT_WRAPPER=1 WT_CD_FILE="$wt_cd_file" command wt "$@"
37
+ local exit_code=$?
38
+ if [[ -f "$wt_cd_file" ]]; then
39
+ local dir=$(cat "$wt_cd_file")
40
+ rm -f "$wt_cd_file"
41
+ [[ -d "$dir" ]] && cd "$dir"
42
+ fi
43
+ return $exit_code
44
+ }`,
45
+ },
46
+ bash: {
47
+ name: 'Bash',
48
+ rcFile: join(home, '.bashrc'),
49
+ wrapper: `
50
+ # wt-cli: Git worktree manager shell integration
51
+ wt() {
52
+ local wt_cd_file="/tmp/wt_cd_$$"
53
+ rm -f "$wt_cd_file"
54
+ WT_WRAPPER=1 WT_CD_FILE="$wt_cd_file" command wt "$@"
55
+ local exit_code=$?
56
+ if [[ -f "$wt_cd_file" ]]; then
57
+ local dir=$(cat "$wt_cd_file")
58
+ rm -f "$wt_cd_file"
59
+ [[ -d "$dir" ]] && cd "$dir"
60
+ fi
61
+ return $exit_code
62
+ }`,
63
+ },
64
+ fish: {
65
+ name: 'Fish',
66
+ rcFile: join(home, '.config/fish/config.fish'),
67
+ wrapper: `
68
+ # wt-cli: Git worktree manager shell integration
69
+ function wt
70
+ set -l wt_cd_file "/tmp/wt_cd_fish_$fish_pid"
71
+ rm -f "$wt_cd_file"
72
+ env WT_WRAPPER=1 WT_CD_FILE="$wt_cd_file" command wt $argv
73
+ set -l exit_code $status
74
+ if test -f "$wt_cd_file"
75
+ set -l dir (cat "$wt_cd_file")
76
+ rm -f "$wt_cd_file"
77
+ test -d "$dir"; and cd "$dir"
78
+ end
79
+ return $exit_code
80
+ end`,
81
+ },
82
+ };
83
+ return configs[shell] || null;
84
+ }
85
+ export function isWrapperInstalled() {
86
+ // Check if we're running through the wrapper
87
+ // The wrapper would need to set this env var
88
+ return process.env.WT_WRAPPER === '1';
89
+ }
90
+ export function checkWrapperInRcFile() {
91
+ const config = getShellConfig();
92
+ if (!config)
93
+ return { installed: false, reason: 'unknown-shell' };
94
+ if (!existsSync(config.rcFile)) {
95
+ return { installed: false, reason: 'no-rc-file', rcFile: config.rcFile };
96
+ }
97
+ try {
98
+ const content = readFileSync(config.rcFile, 'utf-8');
99
+ if (content.includes('wt-cli') || content.includes('__WT_CD__')) {
100
+ return { installed: true, rcFile: config.rcFile };
101
+ }
102
+ return { installed: false, reason: 'not-configured', rcFile: config.rcFile };
103
+ }
104
+ catch {
105
+ return { installed: false, reason: 'read-error', rcFile: config.rcFile };
106
+ }
107
+ }
108
+ export async function setupCommand() {
109
+ showMiniLogo();
110
+ heading(`${icons.sparkles} Shell Setup`);
111
+ const shell = detectShell();
112
+ const config = getShellConfig();
113
+ if (shell === 'unknown' || !config) {
114
+ warning(`Could not detect your shell type`);
115
+ info(`SHELL environment variable: ${process.env.SHELL || 'not set'}`);
116
+ spacer();
117
+ console.log(` ${colors.muted('Please manually add the shell wrapper to your shell config.')}`);
118
+ console.log(` ${colors.muted('See:')} ${colors.path('https://github.com/jhorst11/wt#shell-integration')}`);
119
+ spacer();
120
+ return;
121
+ }
122
+ success(`Detected shell: ${colors.primary(config.name)}`);
123
+ info(`Config file: ${colors.path(config.rcFile)}`);
124
+ spacer();
125
+ const status = checkWrapperInRcFile();
126
+ if (status.installed) {
127
+ success(`Shell integration is already installed! ${icons.check}`);
128
+ spacer();
129
+ info(`If directory jumping isn't working, try restarting your terminal`);
130
+ info(`or run: ${colors.primary(`source ${config.rcFile}`)}`);
131
+ spacer();
132
+ return;
133
+ }
134
+ // Not installed - offer to install
135
+ divider();
136
+ spacer();
137
+ console.log(` ${colors.muted('To enable directory jumping (wt go, wt home), we need to')}`);
138
+ console.log(` ${colors.muted('add a small shell function to your')} ${colors.path(config.rcFile)}`);
139
+ spacer();
140
+ try {
141
+ const action = await select({
142
+ message: 'How would you like to proceed?',
143
+ choices: [
144
+ {
145
+ name: `${icons.sparkles} Auto-install (append to ${config.rcFile})`,
146
+ value: 'auto',
147
+ description: 'Recommended - automatically adds the integration',
148
+ },
149
+ {
150
+ name: `${icons.info} Show me the code to copy`,
151
+ value: 'show',
152
+ description: 'Display the code so you can add it manually',
153
+ },
154
+ {
155
+ name: `${colors.muted(icons.cross + ' Skip for now')}`,
156
+ value: 'skip',
157
+ },
158
+ ],
159
+ theme: { prefix: icons.tree },
160
+ });
161
+ if (action === 'auto') {
162
+ await autoInstall(config);
163
+ }
164
+ else if (action === 'show') {
165
+ showManualInstructions(config);
166
+ }
167
+ else {
168
+ info('Skipped. You can run `wt setup` anytime to configure shell integration.');
169
+ spacer();
170
+ }
171
+ }
172
+ catch (err) {
173
+ if (err instanceof ExitPromptError) {
174
+ spacer();
175
+ info('Cancelled');
176
+ spacer();
177
+ return;
178
+ }
179
+ throw err;
180
+ }
181
+ }
182
+ async function autoInstall(config) {
183
+ spacer();
184
+ try {
185
+ appendFileSync(config.rcFile, '\n' + config.wrapper + '\n');
186
+ success(`Added shell integration to ${colors.path(config.rcFile)}`);
187
+ spacer();
188
+ console.log(` ${icons.rocket} ${colors.primary('Almost done!')} Run this to activate:`);
189
+ spacer();
190
+ console.log(` ${colors.secondary(`source ${config.rcFile}`)}`);
191
+ spacer();
192
+ console.log(` ${colors.muted('Or just restart your terminal.')}`);
193
+ spacer();
194
+ }
195
+ catch (err) {
196
+ const errorMessage = err instanceof Error ? err.message : String(err);
197
+ error(`Failed to write to ${config.rcFile}`);
198
+ error(errorMessage);
199
+ spacer();
200
+ showManualInstructions(config);
201
+ }
202
+ }
203
+ function showManualInstructions(config) {
204
+ spacer();
205
+ console.log(` ${colors.muted('Add this to')} ${colors.path(config.rcFile)}${colors.muted(':')}`);
206
+ spacer();
207
+ divider();
208
+ console.log(colors.secondary(config.wrapper));
209
+ divider();
210
+ spacer();
211
+ console.log(` ${colors.muted('Then run:')} ${colors.primary(`source ${config.rcFile}`)}`);
212
+ spacer();
213
+ }
214
+ // Helper to show a gentle nudge if wrapper isn't set up
215
+ export function showCdHint(path) {
216
+ // Check if we're running through the shell wrapper with a cd file
217
+ const cdFile = process.env.WT_CD_FILE;
218
+ if (cdFile && isWrapperInstalled()) {
219
+ // Write path to temp file for shell wrapper to read
220
+ try {
221
+ writeFileSync(cdFile, path);
222
+ }
223
+ catch {
224
+ // Fall through to show manual instructions
225
+ }
226
+ return;
227
+ }
228
+ // Fall back to checking rc file
229
+ const status = checkWrapperInRcFile();
230
+ if (status.installed) {
231
+ // Wrapper is in rc file but not active - show path
232
+ spacer();
233
+ console.log(` ${icons.rocket} ${colors.muted('Switching to:')} ${colors.path(path)}`);
234
+ spacer();
235
+ }
236
+ else {
237
+ // No wrapper - show a friendly message instead
238
+ spacer();
239
+ console.log(` ${icons.rocket} ${colors.muted('Run:')} ${colors.primary(`wt go`)} ${colors.muted('or')} ${colors.primary(`cd "${path}"`)}`);
240
+ spacer();
241
+ console.log(` ${colors.muted(`Tip: Run`)} ${colors.secondary('wt setup')} ${colors.muted('to enable auto-navigation')}`);
242
+ spacer();
243
+ }
244
+ }
245
+ //# sourceMappingURL=setup.js.map