@liangmi/mo 0.0.5 → 1.0.1
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 +32 -101
- package/config_schema.json +16 -0
- package/dist/chunk-CBBoxR_p.mjs +26 -0
- package/dist/devtools-BHS22BGO.mjs +3569 -0
- package/dist/mo-inner.mjs +26 -34
- package/dist/mo.mjs +25698 -4890
- package/dist/{runner-BDAeQY-R.mjs → runner-DW0Q4OMK.mjs} +16 -29
- package/package.json +8 -5
package/dist/mo-inner.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
1
|
+
import { c as getDefaultConfigPath, d as error, l as loadConfig, n as getRestartFlagPath, r as innerBinName, u as supportedShells, w as cac, y as buildAliasLines } from "./runner-DW0Q4OMK.mjs";
|
|
2
|
+
import { existsSync, readFileSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
3
5
|
//#region src/inner/shell.ts
|
|
4
6
|
function generateShellIntegration(shell) {
|
|
5
7
|
if (!isValidShell(shell)) error(`Invalid shell "${shell}". Supported: ${supportedShells.join(", ")}`);
|
|
@@ -8,53 +10,40 @@ function generateShellIntegration(shell) {
|
|
|
8
10
|
else return generateFishIntegration(aliases);
|
|
9
11
|
}
|
|
10
12
|
function generateBashZshIntegration(aliases) {
|
|
13
|
+
const lines = buildAliasLines(aliases, (name, target) => `alias ${name}='${target}'`);
|
|
11
14
|
return [
|
|
12
15
|
"# mo shell integration script",
|
|
16
|
+
`# Clear restart flag if present (setup completed in previous shell)`,
|
|
17
|
+
`rm -f "${getRestartFlagPath()}" 2>/dev/null || true`,
|
|
13
18
|
"mo() {",
|
|
14
|
-
"
|
|
15
|
-
" shift",
|
|
16
|
-
" local mo_cd_target",
|
|
17
|
-
" mo_cd_target=\"$(command mo cd \"$@\")\" || return $?",
|
|
18
|
-
" export MO_CD_TARGET=\"$mo_cd_target\"",
|
|
19
|
-
" else",
|
|
20
|
-
" command mo \"$@\" || return $?",
|
|
21
|
-
" fi",
|
|
22
|
-
"",
|
|
19
|
+
" command mo \"$@\" || return $?",
|
|
23
20
|
" local mo_cd_result",
|
|
24
21
|
" mo_cd_result=\"$(mo-inner cd)\" || return $?",
|
|
25
22
|
" if [ -n \"$mo_cd_result\" ] && [ \"$mo_cd_result\" != \".\" ]; then",
|
|
26
23
|
" cd \"$mo_cd_result\" || return $?",
|
|
27
24
|
" fi",
|
|
28
|
-
"",
|
|
29
|
-
" unset MO_CD_TARGET",
|
|
30
25
|
"}",
|
|
31
|
-
...
|
|
26
|
+
...lines,
|
|
32
27
|
""
|
|
33
28
|
].join("\n");
|
|
34
29
|
}
|
|
35
30
|
function generateFishIntegration(aliases) {
|
|
31
|
+
const lines = buildAliasLines(aliases, (name, target) => `alias ${name} '${target}'`);
|
|
36
32
|
return [
|
|
37
33
|
"# mo shell integration script",
|
|
34
|
+
"# Clear restart flag if present (setup completed in previous shell)",
|
|
35
|
+
`rm -f "${getRestartFlagPath()}" 2>/dev/null; or true`,
|
|
38
36
|
"function mo",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
" or return $status",
|
|
42
|
-
" set -gx MO_CD_TARGET \"$mo_cd_target\"",
|
|
43
|
-
" else",
|
|
44
|
-
" command mo $argv",
|
|
45
|
-
" or return $status",
|
|
46
|
-
" end",
|
|
47
|
-
"",
|
|
37
|
+
" command mo $argv",
|
|
38
|
+
" or return $status",
|
|
48
39
|
" set -l mo_cd_result (mo-inner cd)",
|
|
49
40
|
" or return $status",
|
|
50
41
|
" if test -n \"$mo_cd_result\"; and test \"$mo_cd_result\" != \".\"",
|
|
51
42
|
" cd \"$mo_cd_result\"",
|
|
52
43
|
" or return $status",
|
|
53
44
|
" end",
|
|
54
|
-
"",
|
|
55
|
-
" set -e MO_CD_TARGET",
|
|
56
45
|
"end",
|
|
57
|
-
...
|
|
46
|
+
...lines,
|
|
58
47
|
""
|
|
59
48
|
].join("\n");
|
|
60
49
|
}
|
|
@@ -70,17 +59,20 @@ function loadAliasConfig() {
|
|
|
70
59
|
}
|
|
71
60
|
}
|
|
72
61
|
//#endregion
|
|
62
|
+
//#region src/inner/cd.ts
|
|
63
|
+
function getCdPath() {
|
|
64
|
+
const targetFile = path.join(tmpdir(), "mo-cd-target");
|
|
65
|
+
if (!existsSync(targetFile)) return ".";
|
|
66
|
+
const pending = readFileSync(targetFile, "utf8").trim();
|
|
67
|
+
rmSync(targetFile);
|
|
68
|
+
if (!pending) return ".";
|
|
69
|
+
return pending;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
73
72
|
//#region src/mo-inner.ts
|
|
74
73
|
const cli = cac(innerBinName);
|
|
75
74
|
cli.command("shell <shell>", "Generate shell integration code").action((shell) => console.log(generateShellIntegration(shell)));
|
|
76
|
-
cli.command("cd", "Print pending directory path from shell state").action(() =>
|
|
77
|
-
const pending = process.env.MO_CD_TARGET;
|
|
78
|
-
if (typeof pending !== "string" || !pending.trim()) {
|
|
79
|
-
console.log(".");
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
console.log(pending);
|
|
83
|
-
});
|
|
75
|
+
cli.command("cd", "Print pending directory path from shell state").action(() => console.log(getCdPath()));
|
|
84
76
|
cli.parse();
|
|
85
77
|
//#endregion
|
|
86
78
|
export {};
|