caroushell 0.1.16 → 0.1.18
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 -10
- package/dist/spawner.js +6 -4
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ class HistorySuggester {
|
|
|
11
11
|
constructor(filePath) {
|
|
12
12
|
this.prefix = "⌛";
|
|
13
13
|
this.items = [];
|
|
14
|
+
this.filteredItems = [];
|
|
14
15
|
this.maxItems = 1000;
|
|
15
16
|
const home = process.env.HOME || process.env.USERPROFILE || process.cwd();
|
|
16
17
|
// Default path: ~/.caroushell/history
|
|
@@ -24,9 +25,11 @@ class HistorySuggester {
|
|
|
24
25
|
try {
|
|
25
26
|
const data = await fs_1.promises.readFile(this.filePath, "utf8");
|
|
26
27
|
this.items = this.parseHistory(data);
|
|
28
|
+
this.filteredItems = this.items;
|
|
27
29
|
}
|
|
28
30
|
catch {
|
|
29
31
|
this.items = [];
|
|
32
|
+
this.filteredItems = [];
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
async add(command) {
|
|
@@ -45,29 +48,26 @@ class HistorySuggester {
|
|
|
45
48
|
await fs_1.promises.appendFile(this.filePath, this.serializeHistoryEntry(command), "utf8");
|
|
46
49
|
}
|
|
47
50
|
latest() {
|
|
48
|
-
return this.
|
|
51
|
+
return this.filteredItems;
|
|
49
52
|
}
|
|
50
53
|
async refreshSuggestions(carousel, maxDisplayed) {
|
|
51
54
|
const input = carousel.getCurrentRow();
|
|
52
|
-
let
|
|
53
|
-
if (
|
|
54
|
-
//
|
|
55
|
-
results = this.items;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
55
|
+
let suggestedItems = this.items;
|
|
56
|
+
if (input) {
|
|
57
|
+
// filter by input substring
|
|
58
58
|
const q = input.toLowerCase();
|
|
59
|
-
|
|
59
|
+
suggestedItems = [];
|
|
60
60
|
// iterate from newest to oldest so we skip older duplicates
|
|
61
61
|
const seen = new Set();
|
|
62
62
|
for (let i = 0; i < this.items.length; i++) {
|
|
63
63
|
const it = this.items[i];
|
|
64
64
|
if (it.toLowerCase().includes(q) && !seen.has(it)) {
|
|
65
65
|
seen.add(it);
|
|
66
|
-
|
|
66
|
+
suggestedItems.push(it);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
results = matched;
|
|
70
69
|
}
|
|
70
|
+
this.filteredItems = suggestedItems;
|
|
71
71
|
carousel.render();
|
|
72
72
|
}
|
|
73
73
|
descriptionForAi() {
|
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);
|