caroushell 0.1.11 → 0.1.12

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/app.js CHANGED
@@ -208,6 +208,7 @@ class App {
208
208
  return true;
209
209
  }
210
210
  tryAcceptHighlightedFileSuggestion() {
211
+ // After ENTER on a file suggestion, we want to place the match at the cursor
211
212
  const currentSuggester = this.carousel.getCurrentRowSuggester();
212
213
  if (currentSuggester !== this.files)
213
214
  return false;
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.FileSuggester = void 0;
4
7
  const fs_1 = require("fs");
8
+ const os_1 = __importDefault(require("os"));
9
+ const path_1 = __importDefault(require("path"));
5
10
  const maxFileAiLines = 10;
6
11
  class FileSuggester {
7
12
  constructor() {
@@ -22,11 +27,53 @@ class FileSuggester {
22
27
  }
23
28
  async getMatchingFiles(queryRaw) {
24
29
  await this.refreshFiles();
25
- const query = queryRaw.trim().toLowerCase();
26
- if (!query) {
27
- return [...this.files];
30
+ const query = queryRaw.trim();
31
+ const { dirDisplay, fragment, dirPath } = this.parseQuery(query);
32
+ const entries = await this.readDirectory(dirPath);
33
+ const needle = fragment.toLowerCase();
34
+ return entries
35
+ .filter((entry) => entry.toLowerCase().startsWith(needle))
36
+ .map((entry) => `${dirDisplay}${entry}`);
37
+ }
38
+ async readDirectory(dirPath) {
39
+ try {
40
+ const entries = await fs_1.promises.readdir(dirPath);
41
+ return entries.sort((a, b) => a.localeCompare(b));
42
+ }
43
+ catch {
44
+ return [];
45
+ }
46
+ }
47
+ parseQuery(query) {
48
+ const lastForward = query.lastIndexOf("/");
49
+ const lastBackward = query.lastIndexOf("\\");
50
+ const lastSeparator = Math.max(lastForward, lastBackward);
51
+ if (lastSeparator === -1) {
52
+ return {
53
+ dirDisplay: "",
54
+ fragment: query,
55
+ dirPath: process.cwd(),
56
+ };
57
+ }
58
+ const dirDisplay = query.slice(0, lastSeparator + 1);
59
+ const fragment = query.slice(lastSeparator + 1);
60
+ return {
61
+ dirDisplay,
62
+ fragment,
63
+ dirPath: this.resolveDirectory(dirDisplay),
64
+ };
65
+ }
66
+ resolveDirectory(dirDisplay) {
67
+ if (!dirDisplay) {
68
+ return process.cwd();
69
+ }
70
+ if (dirDisplay.startsWith("~")) {
71
+ const rest = dirDisplay.slice(1);
72
+ const normalizedRest = rest.replace(/^[\\/]/, "");
73
+ return path_1.default.resolve(os_1.default.homedir(), normalizedRest.replace(/\//g, path_1.default.sep));
28
74
  }
29
- return this.files.filter((file) => file.toLowerCase().indexOf(query.toLowerCase()) === 0);
75
+ const converted = dirDisplay.replace(/\//g, path_1.default.sep);
76
+ return path_1.default.resolve(process.cwd(), converted);
30
77
  }
31
78
  async suggest(carousel, maxDisplayed) {
32
79
  const { prefix } = carousel.getWordInfoAtCursor();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caroushell",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Terminal carousel that suggests commands from history, config, and AI.",
5
5
  "type": "commonjs",
6
6
  "main": "dist/main.js",