pf 0.0.4 → 0.0.6
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/LICENSE +21 -0
- package/README.md +227 -25
- package/dist/index.js +7081 -1770
- package/package.json +30 -7
- package/.github/workflows/publish.yml +0 -29
- package/.husky/pre-push +0 -1
- package/build.ts +0 -24
- package/commands/completion.ts +0 -197
- package/commands/ls.ts +0 -49
- package/commands/new.ts +0 -82
- package/commands/open.ts +0 -61
- package/commands/rm.ts +0 -61
- package/go/Makefile +0 -37
- package/go/cmd/completion.go +0 -183
- package/go/cmd/list.go +0 -126
- package/go/cmd/new.go +0 -146
- package/go/cmd/open.go +0 -128
- package/go/cmd/rm.go +0 -88
- package/go/cmd/root.go +0 -74
- package/go/cmd/styles.go +0 -9
- package/go/cmd/version.go +0 -27
- package/go/cmd/where.go +0 -57
- package/go/go.mod +0 -37
- package/go/go.sum +0 -73
- package/go/internal/store/store.go +0 -124
- package/go/main.go +0 -7
- package/index.ts +0 -107
- package/scripts/check-version.ts +0 -20
- package/store.ts +0 -67
- package/tsconfig.json +0 -16
- package/utils.ts +0 -108
package/utils.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { execSync, spawnSync } from "child_process";
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { dirname } from "path";
|
|
4
|
-
import pc from "picocolors";
|
|
5
|
-
import { getGitCommonDir, getGitRoot } from "./store.js";
|
|
6
|
-
|
|
7
|
-
export function getCurrentBranch(): string {
|
|
8
|
-
try {
|
|
9
|
-
return execSync("git branch --show-current", { encoding: "utf-8" }).trim() || "HEAD";
|
|
10
|
-
} catch {
|
|
11
|
-
return "HEAD";
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function getWorktreeBranch(path: string): string {
|
|
16
|
-
if (!existsSync(path)) {
|
|
17
|
-
return "[missing]";
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
const branch = execSync(`git -C "${path}" branch --show-current`, { encoding: "utf-8" }).trim();
|
|
21
|
-
return branch || "[detached]";
|
|
22
|
-
} catch {
|
|
23
|
-
return "[detached]";
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function getWorktreeStatus(path: string): string {
|
|
28
|
-
if (!existsSync(path)) {
|
|
29
|
-
return "";
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
const status = execSync(`git -C "${path}" status --porcelain`, { encoding: "utf-8" }).trim();
|
|
33
|
-
if (!status) {
|
|
34
|
-
return "clean";
|
|
35
|
-
}
|
|
36
|
-
const lines = status.split("\n").length;
|
|
37
|
-
return `${lines} changed`;
|
|
38
|
-
} catch {
|
|
39
|
-
return "[error]";
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function branchExists(name: string): boolean {
|
|
44
|
-
try {
|
|
45
|
-
execSync(`git show-ref --verify --quiet refs/heads/${name}`);
|
|
46
|
-
return true;
|
|
47
|
-
} catch {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function isInsideWorktree(): boolean {
|
|
53
|
-
try {
|
|
54
|
-
const gitRoot = getGitRoot();
|
|
55
|
-
const gitDir = getGitCommonDir();
|
|
56
|
-
return gitRoot !== dirname(gitDir);
|
|
57
|
-
} catch {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function hasUncommittedChanges(): boolean {
|
|
63
|
-
try {
|
|
64
|
-
const status = execSync("git status --porcelain", { encoding: "utf-8" }).trim();
|
|
65
|
-
return status.length > 0;
|
|
66
|
-
} catch {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function createWorktree(name: string, path: string): void {
|
|
72
|
-
execSync(`git worktree add -b "${name}" "${path}"`, { stdio: "ignore" });
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function removeWorktree(path: string): void {
|
|
76
|
-
execSync(`git worktree remove "${path}"`, { stdio: "ignore" });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function pruneWorktrees(): void {
|
|
80
|
-
try {
|
|
81
|
-
execSync("git worktree prune", { stdio: "ignore" });
|
|
82
|
-
} catch {
|
|
83
|
-
// ignore
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function deleteBranch(name: string): void {
|
|
88
|
-
execSync(`git branch -D "${name}"`, { stdio: "ignore" });
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function generateName(): string {
|
|
92
|
-
const bytes = new Uint8Array(4);
|
|
93
|
-
crypto.getRandomValues(bytes);
|
|
94
|
-
const hex = Array.from(bytes)
|
|
95
|
-
.map((b) => b.toString(16).padStart(2, "0"))
|
|
96
|
-
.join("");
|
|
97
|
-
return `pf-${hex}`;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function spawnShell(cwd: string): void {
|
|
101
|
-
const shell = process.env.SHELL || "/bin/sh";
|
|
102
|
-
spawnSync(shell, { cwd, stdio: "inherit" });
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Styled output helpers
|
|
106
|
-
export const success = (text: string) => pc.green(pc.bold("✓")) + " " + text;
|
|
107
|
-
export const dim = (text: string) => pc.dim(text);
|
|
108
|
-
export const bold = (text: string) => pc.bold(text);
|