You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this stage, you'll extend your shell's tab completion to handle cases with multiple matching executables where one is a prefix of another.
1
+
In this stage, you'll extend autocompletion to handle partial completions using the longest common prefix (LCP) logic.
2
2
3
-
When the user types a partial command and presses the Tab key, your shell should attempt to complete the command name. If there are multiple executable files in the PATH that match the prefix, and one of those matches is a prefix of another, then the shell should complete to the longest common prefix of all matching executables. If there is only one match after performing completion, then the shell should complete the command name as in previous stages.
3
+
### Completing to Longest Common Prefix
4
4
5
-
For example, if `xyz_foo`, `xyz_foo_bar`, and `xyz_foo_bar_baz` are all available executables and the user types `xyz_` and presses tab, then your shell should complete the command to `xyz_foo`. If the user then types `_` and presses tab again, it should complete to `xyz_foo_bar`. If the user then types `_` and presses tab again, it should complete to `xyz_foo_bar_baz`.
5
+
When multiple executables match the user's input, and some are prefixes of others, your shell should complete to the longest common prefix of all matches.
6
+
7
+
For example, if these executables exist in PATH:
8
+
9
+
-`xyz_foo`
10
+
-`xyz_foo_bar`
11
+
-`xyz_foo_bar_baz`
12
+
13
+
When the user types `xyz_` and presses tab, the shell completes to `xyz_foo` because that is the longest prefix shared by all three executables.
14
+
15
+
After the user types the next separator character, pressing tab completes to the next common prefix of the remaining matches:
16
+
17
+
```bash
18
+
# Note: The prompt lines below are displayed on the same line
19
+
$ xyz_<TAB>
20
+
$ xyz_foo_<TAB>
21
+
$ xyz_foo_bar_<TAB>
22
+
$ xyz_foo_bar_baz
23
+
```
24
+
25
+
If there is only one match after performing completion, then the shell should complete the command name as with previous stages (with a trailing space).
6
26
7
27
### Tests
8
28
@@ -12,25 +32,18 @@ The tester will execute your program like this:
12
32
./your_program.sh
13
33
```
14
34
15
-
It will then set up a specific `PATH` and place executables `xyz_foo`, `xyz_foo_bar`, and `xyz_foo_bar_baz` into different directories in the `PATH`. Finally, it will type `xyz_` and then press Tab, then type `_` and press Tab, then type `_` and press Tab.
35
+
It will then test progressive tab completion:
16
36
17
37
```bash
18
-
$ export PATH=/tmp/bar:$PATH
19
-
$ export PATH=/tmp/baz:$PATH
20
-
$ export PATH=/tmp/qux:$PATH
21
-
$ ./your_program.sh
38
+
# Note: The prompt lines below are displayed on the same line
22
39
$ xyz_<TAB>
23
40
$ xyz_foo_<TAB>
24
41
$ xyz_foo_bar_<TAB>
25
-
$ xyz_foo_bar_baz
42
+
$ xyz_foo_bar_baz
26
43
```
27
-
Note: The prompt lines above are on the same line.
28
44
29
45
The tester will verify that:
30
-
31
-
1. After typing `xyz_` and pressing Tab, your shell completes to `xyz_foo`.
32
-
2. After typing `_`, the prompt line matches `$ xyz_foo_`.
33
-
3. After typing `_` and pressing Tab, your shell completes to `xyz_foo_bar`.
34
-
4. After typing `_`, the prompt line matches `$ xyz_foo_bar_`.
35
-
5. After typing `_` and pressing Tab, your shell completes to `xyz_foo_bar_baz`.
36
-
6. The prompt line matches `$ xyz_foo_bar_baz ` after the final completion.
46
+
1. After `xyz_`<TAB>, the completion shows `xyz_foo`.
47
+
2. After typing `_` and pressing tab, the completion shows `xyz_foo_bar`.
48
+
3. After typing `_` and pressing tab again, the completion shows `xyz_foo_bar_baz ` with a trailing space.
49
+
4. The trailing space only appears when exactly one match remains.
0 commit comments