Skip to content

Commit e0274d0

Browse files
tab complete for most built in programs (no file paths yet)
1 parent 30e2434 commit e0274d0

24 files changed

Lines changed: 68 additions & 14 deletions

src/programs/alias.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default {
88
name: "The name of the alias to define or display. If no arguments are given, all aliases are displayed. Multiple alias arguments can be provided.",
99
"name=value": "Defines an alias with the given name and value. End the value with a space to allow chaining."
1010
},
11+
completion: async () => [],
1112
main: async (data) => {
1213
// extract from data to make code less verbose
1314
const { term } = data;

src/programs/ascmagine.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default {
2727
"-u": "Path is an web URL instead of a local filesystem path."
2828
}
2929
},
30+
// TODO: completion
3031
main: async (data) => {
3132
// extract from data to make code less verbose
3233
const { args, term } = data;

src/programs/clear.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ANSI } from "../term_ctl";
22
import type { Program } from "../types";
3+
import {helper_completion_options} from "../tab_completion";
34

45
export default {
56
name: "clear",
@@ -12,6 +13,7 @@ export default {
1213
"-so": "Only clear the scrollback."
1314
}
1415
},
16+
completion: helper_completion_options(["-h", "-s", "-so"]),
1517
main: async (data) => {
1618
// extract from data to make code less verbose
1719
const { args, term } = data;

src/programs/echo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default {
99
"string": "The string to echo."
1010
}
1111
},
12+
completion: async () => [],
1213
main: async (data) => {
1314
// extract from data to make code less verbose
1415
const { args, term } = data;

src/programs/hex.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Program } from "../types";
22
import { ANSI } from "../term_ctl";
3+
import {helper_completion_options} from "../tab_completion";
34

45
// TODO: when edit is done, add a flag to edit the file in the editor
56

@@ -16,6 +17,20 @@ export default {
1617
"-i": "Print indexes."
1718
}
1819
},
20+
completion: async (data) => {
21+
// use default logic for first argument
22+
if (data.arg_index === 0) {
23+
return null;
24+
}
25+
26+
if (data.arg_index === 1) {
27+
if ("-i".startsWith(data.current_partial)) {
28+
return ["-i"];
29+
}
30+
}
31+
32+
return [];
33+
},
1934
main: async (data) => {
2035
// extract from data to make code less verbose
2136
const { args, term } = data;

src/programs/imagine.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export default {
5757
"-u": "Path is an web URL instead of a local filesystem path."
5858
}
5959
},
60+
// TODO: completion
6061
main: async (data) => {
6162
// extract from data to make code less verbose
6263
const { args, term } = data;

src/programs/legacy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export default {
44
name: "legacy",
55
description: "Opens the legacy ollieg.codes site if you're having trouble with this version.",
66
usage_suffix: "",
7-
arg_descriptions: {
8-
},
7+
arg_descriptions: {},
8+
completion: async () => [],
99
main: async (_data) => {
1010
window.location.assign("https://legacy.ollieg.codes/");
1111

src/programs/mefetch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export default {
110110
arg_descriptions: {
111111
"username": "The GitHub username to show basic info about. Defaults to my username, with the special info shown."
112112
},
113+
completion: async () => [],
113114
main: async (data) => {
114115
// extract from data to make code less verbose
115116
const { term, args } = data;

src/programs/mkdir.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default {
1313
"directory": "The directory to create."
1414
}
1515
},
16+
completion: async () => [],
1617
main: async (data) => {
1718
// extract from data to make code less verbose
1819
const { args, term } = data;

src/programs/pkg/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,11 @@ export default {
455455
}
456456
},
457457
completion: async (data) => {
458-
const arg_index = data.raw_parts.length - 1;
459-
460458
// TODO: smarter completion that understands flags for subcommands
461-
switch (arg_index) {
459+
switch (data.arg_index) {
460+
case 0:
461+
return helper_completion_options(["add", "remove", "list", "info", "read", "browse", "clean"])(data);
462462
case 1:
463-
return helper_completion_options(["add", "remove", "list", "info", "read", "browse", "clean", "-h"])(data);
464-
case 2:
465463
if (["info", "read", "remove"].includes(data.args[0])) {
466464
// complete with installed package names
467465
const fs = data.term.get_fs();

0 commit comments

Comments
 (0)