caroushell 0.1.17 → 0.1.19
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/dist/history-suggester.js +10 -8
- package/dist/spawner.js +6 -4
- package/package.json +2 -1
|
@@ -10,6 +10,7 @@ const config_1 = require("./config");
|
|
|
10
10
|
class HistorySuggester {
|
|
11
11
|
constructor(filePath) {
|
|
12
12
|
this.prefix = "⌛";
|
|
13
|
+
// `items` is the history as a list of commands, with the most recent at index 0
|
|
13
14
|
this.items = [];
|
|
14
15
|
this.filteredItems = [];
|
|
15
16
|
this.maxItems = 1000;
|
|
@@ -71,18 +72,19 @@ class HistorySuggester {
|
|
|
71
72
|
carousel.render();
|
|
72
73
|
}
|
|
73
74
|
descriptionForAi() {
|
|
75
|
+
// This goes into the prompt
|
|
74
76
|
const lines = [];
|
|
75
77
|
const maxHistoryLines = 20;
|
|
76
|
-
const start =
|
|
77
|
-
const end =
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
lines.push(`The most recent command is: "${
|
|
78
|
+
const start = 0;
|
|
79
|
+
const end = maxHistoryLines;
|
|
80
|
+
const newToOldSlice = this.items.slice(start, end);
|
|
81
|
+
if (newToOldSlice.length > 0) {
|
|
82
|
+
lines.push(`The most recent command is: "${newToOldSlice[0]}"`);
|
|
81
83
|
}
|
|
82
|
-
if (
|
|
84
|
+
if (newToOldSlice.length > 1) {
|
|
83
85
|
lines.push("The most recent commands are (from recent to oldest):");
|
|
84
|
-
for (let i = 0; i <
|
|
85
|
-
lines.push(` ${i + 1}. ${
|
|
86
|
+
for (let i = 0; i < newToOldSlice.length; i++) {
|
|
87
|
+
lines.push(` ${i + 1}. ${newToOldSlice[i]}`);
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
return lines.join("\n");
|
package/dist/spawner.js
CHANGED
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.runUserCommand = runUserCommand;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const process_1 = require("process");
|
|
6
|
+
const logs_1 = require("./logs");
|
|
6
7
|
const isWin = process.platform === "win32";
|
|
7
8
|
const shellBinary = isWin ? "cmd.exe" : "/bin/bash";
|
|
8
|
-
const shellArgs = isWin ? ["/c"] : ["-lc"];
|
|
9
|
+
const shellArgs = isWin ? ["/d", "/s", "/c"] : ["-lc"];
|
|
9
10
|
const builtInCommands = {
|
|
10
11
|
cd: async (args) => {
|
|
11
12
|
if (args.length === 1) {
|
|
@@ -47,6 +48,7 @@ function expandVars(input) {
|
|
|
47
48
|
return out;
|
|
48
49
|
}
|
|
49
50
|
async function runUserCommand(command) {
|
|
51
|
+
(0, logs_1.logLine)(`Running command: ${command}`);
|
|
50
52
|
const trimmed = command.trim();
|
|
51
53
|
if (!trimmed)
|
|
52
54
|
return false;
|
|
@@ -54,11 +56,11 @@ async function runUserCommand(command) {
|
|
|
54
56
|
if (typeof args[0] === "string" && builtInCommands[args[0]]) {
|
|
55
57
|
return await builtInCommands[args[0]](args);
|
|
56
58
|
}
|
|
57
|
-
// "
|
|
58
|
-
// \"
|
|
59
|
+
// "windowsVerbatimArguments: true" to prevent the bug of `echo "asdf"` outputting
|
|
60
|
+
// \"asdf\" instead of "asdf". I wonder why node defaults to quoting args on windows.
|
|
59
61
|
const proc = (0, child_process_1.spawn)(shellBinary, [...shellArgs, command], {
|
|
60
62
|
stdio: "inherit",
|
|
61
|
-
|
|
63
|
+
windowsVerbatimArguments: true,
|
|
62
64
|
});
|
|
63
65
|
await new Promise((resolve, reject) => {
|
|
64
66
|
proc.on("error", reject);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "caroushell",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"description": "Terminal carousel that suggests commands from history, config, and AI.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"build": "tsc -p tsconfig.release.json",
|
|
18
18
|
"prepare": "npm run build",
|
|
19
19
|
"start": "node dist/main.js",
|
|
20
|
+
"test": "node --import tsx --test tests/history-suggester.test.ts",
|
|
20
21
|
"test:generate": "tsx src/test-generate.ts",
|
|
21
22
|
"lint": "eslint . --ext .ts",
|
|
22
23
|
"release": "tsx scripts/release.ts"
|