Skip to content

Commit 6bf9bfd

Browse files
add autocomplete to window command
1 parent af66936 commit 6bf9bfd

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/programs/pkg/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,10 @@ export default {
457457
completion: async (data) => {
458458
const arg_index = data.raw_parts.length - 1;
459459

460+
// TODO: smarter completion that understands flags for subcommands
460461
switch (arg_index) {
461462
case 1:
462-
return helper_completion_options(["add", "remove", "list", "info", "read", "browse", "clean"])(data);
463+
return helper_completion_options(["add", "remove", "list", "info", "read", "browse", "clean", "-h"])(data);
463464
case 2:
464465
if (["info", "read", "remove"].includes(data.args[0])) {
465466
// complete with installed package names
@@ -474,7 +475,7 @@ export default {
474475
}
475476

476477
const pkgs = Object.keys(local_graph);
477-
return pkgs.filter((pkg) => pkg.startsWith(data.current_partial));
478+
return helper_completion_options(pkgs)(data);
478479
}
479480
break;
480481
}

src/programs/window/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {show_subcommand} from "./show";
77
import {hide_subcommand} from "./hide";
88
import {close_subcommand} from "./close";
99
import {center_subcommand} from "./center";
10+
import {helper_completion_options} from "../../tab_completion";
1011

1112
// extract from ANSI to make code less verbose
1213
const {STYLE, PREFABS} = ANSI;
@@ -37,6 +38,32 @@ export default {
3738
}
3839
}
3940
},
41+
completion: async (data) => {
42+
const arg_index = data.raw_parts.length - 1;
43+
44+
switch (arg_index) {
45+
case 1:
46+
return helper_completion_options(["info", "list", "show", "hide", "close", "center"])(data);
47+
case 2:
48+
// completing first argument of subcommand
49+
if (data.raw_parts[1] === "list") {
50+
return helper_completion_options(["-v", "-i"])(data);
51+
} else if (["show", "hide", "close", "center"].includes(data.raw_parts[1])) {
52+
// complete window ids
53+
const term = data.term;
54+
const wm = term.get_window_manager();
55+
if (!wm) {
56+
return [];
57+
}
58+
59+
const window_ids = wm.get_all_windows().map((win) => win.id.toString());
60+
return helper_completion_options(window_ids)(data);
61+
}
62+
return [];
63+
default:
64+
return [];
65+
}
66+
},
4067
main: async (data) => {
4168
// extract from data to make code less verbose
4269
const {args, term} = data;

0 commit comments

Comments
 (0)