pf 0.0.1 → 0.0.2
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/.github/workflows/publish.yml +33 -0
- package/build.mjs +24 -0
- package/commands/completion.ts +197 -0
- package/commands/ls.ts +49 -0
- package/commands/new.ts +82 -0
- package/commands/open.ts +61 -0
- package/commands/rm.ts +61 -0
- package/dist/index.js +2316 -0
- package/go/Makefile +37 -0
- package/go/cmd/completion.go +183 -0
- package/go/cmd/list.go +126 -0
- package/go/cmd/new.go +146 -0
- package/go/cmd/open.go +128 -0
- package/go/cmd/rm.go +88 -0
- package/go/cmd/root.go +74 -0
- package/go/cmd/styles.go +9 -0
- package/go/cmd/version.go +27 -0
- package/go/cmd/where.go +57 -0
- package/go/go.mod +37 -0
- package/go/go.sum +73 -0
- package/go/internal/store/store.go +124 -0
- package/go/main.go +7 -0
- package/index.ts +107 -0
- package/package.json +20 -22
- package/store.ts +67 -0
- package/tsconfig.json +16 -0
- package/utils.ts +108 -0
- package/.npmignore +0 -1
- package/index.js +0 -90
- package/test.js +0 -14
package/utils.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
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);
|
package/.npmignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
node_modules
|
package/index.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/*jslint node: true */
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
var _ = require('lodash');
|
|
6
|
-
|
|
7
|
-
function dsl(actions) {
|
|
8
|
-
var obj = Object.create(dsl.prototype);
|
|
9
|
-
obj._actions = actions || [];
|
|
10
|
-
return obj;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
['methods', 'call'].forEach(function (key) {
|
|
14
|
-
dsl[key] = function () {
|
|
15
|
-
var inst = dsl();
|
|
16
|
-
return inst[key].apply(inst, arguments);
|
|
17
|
-
};
|
|
18
|
-
dsl.prototype[key] = function () {
|
|
19
|
-
return dsl(this._actions.concat([[key, _.toArray(arguments)]]));
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
dsl.prototype.done = function () {
|
|
24
|
-
/**
|
|
25
|
-
* Methods for DSL
|
|
26
|
-
*/
|
|
27
|
-
var methods = this._actions.filter(function (a) {
|
|
28
|
-
return a[0] === 'methods';
|
|
29
|
-
}).reduce(function (a, b) {
|
|
30
|
-
return a.concat(b[1][0]);
|
|
31
|
-
}, []);
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Callable methods
|
|
35
|
-
*/
|
|
36
|
-
var method_fns = this._actions.filter(function (a) {
|
|
37
|
-
return a[0] === 'call' && typeof a[1][0] !== 'function';
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Is this DSL callable? If it is, it makes our code a less efficient,
|
|
42
|
-
* because we can't do object delegation with functions.
|
|
43
|
-
*/
|
|
44
|
-
var callable = _.find(this._actions, function (a) {
|
|
45
|
-
return a[0] === 'call' && typeof a[1][0] === 'function';
|
|
46
|
-
});
|
|
47
|
-
if (callable) {
|
|
48
|
-
callable = callable[1][0];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var create, prototype = {};
|
|
52
|
-
|
|
53
|
-
if (callable) {
|
|
54
|
-
create = function (opts) {
|
|
55
|
-
var obj = function () {
|
|
56
|
-
return callable.apply(obj, arguments);
|
|
57
|
-
};
|
|
58
|
-
_.extend(obj, prototype, opts);
|
|
59
|
-
obj._actions = obj._actions || [];
|
|
60
|
-
console.log('actions', obj._actions);
|
|
61
|
-
|
|
62
|
-
return obj;
|
|
63
|
-
};
|
|
64
|
-
} else {
|
|
65
|
-
throw new Error('@TODO non-callable DSL');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
methods.forEach(function (method) {
|
|
69
|
-
prototype[method] = function () {
|
|
70
|
-
return create({
|
|
71
|
-
_actions: this._actions.concat([[method, _.toArray(arguments)]])
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
console.log('rwarr!!!', this, prototype);
|
|
77
|
-
return create();
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
var pf = dsl
|
|
81
|
-
.methods(['curry'])
|
|
82
|
-
.call(function (fn) {
|
|
83
|
-
if (!this._fn) {
|
|
84
|
-
return {_fn: fn};
|
|
85
|
-
}
|
|
86
|
-
console.log('rawrrr!', this._actions);
|
|
87
|
-
})
|
|
88
|
-
.done();
|
|
89
|
-
|
|
90
|
-
pf.curry('foo').curry('bar')('hello');
|
package/test.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
var test = require('tap').test;
|
|
2
|
-
|
|
3
|
-
test('curry examples', function (t) {
|
|
4
|
-
function fn(a, b, c, d) {
|
|
5
|
-
return [a, b, c, d].join();
|
|
6
|
-
}
|
|
7
|
-
function okay_sir(str) {
|
|
8
|
-
t.equals(str, 'hello,world,foo,bar');
|
|
9
|
-
}
|
|
10
|
-
okay_sir(pf(fn).curry('hello', 'world')('foo', 'bar'));
|
|
11
|
-
okay_sir(pf.curry(fn, 'hello', 'world')('foo', 'bar'));
|
|
12
|
-
okay_sir(pf.curry('hello')(fn).curry('world')('foo', 'bar'));
|
|
13
|
-
t.end();
|
|
14
|
-
});
|