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 implement tab completion for executables, specifically when multiple executables share a common prefix.
1
+
In this stage, you'll implement tab completion for multiple executables that share a common prefix.
2
2
3
-
When the user types a command prefix and presses `<TAB>`, your shell should:
3
+
### Handling Multiple Matches
4
4
5
-
- Identify all executables in the `PATH` that match the prefix.
6
-
- If there are multiple matches,
7
-
- On the first TAB press, just ring a bell. (`\a` rings the bell)
8
-
- On the second TAB press, print all the matching executables separated by 2 spaces, on the next line, and follow it with the prompt on a new line.
5
+
When a user types a command prefix and presses `<TAB>`, your shell should find all executables in PATH that match the prefix and do the following:
6
+
7
+
1. On the first `<TAB>` press, ring the bell (using `\x07`).
8
+
2. On the second `<TAB>` press:
9
+
- Print all matching executables on a new line. List them in **alphabetical order**, separated by two spaces (<codestyle="white-space: pre;"> </code>).
10
+
- Show the prompt again on the next line, keeping the original command prefix.
11
+
12
+
For example:
13
+
14
+
```bash
15
+
$ xyz_<TAB><TAB>
16
+
xyz_bar xyz_baz xyz_quz
17
+
$ xyz_
18
+
```
9
19
10
20
### Tests
11
21
@@ -15,17 +25,19 @@ The tester will execute your program like this:
15
25
./your_program.sh
16
26
```
17
27
18
-
It will then set up a specific `PATH` and place multiple executables starting with a common prefix into different directories in the `PATH`. Finally, it will type the common prefix, and then press the Tab key twice.
28
+
It will then set up a specific `PATH` and place multiple executables starting with a common prefix into different directories in the `PATH`.
29
+
30
+
Finally, it will type the common prefix, and then press the tab key twice.
19
31
20
32
```bash
21
-
$ ./your_program.sh
22
33
$ xyz_<TAB><TAB>
23
34
xyz_bar xyz_baz xyz_quz
24
35
$ xyz_
25
36
```
26
37
27
38
The tester will verify that:
28
-
29
-
1. Your shell displays the prompt with the common prefix after receiving the partial command.
30
-
2. Upon the first Tab key press, your shell prints a bell character.
31
-
3. Upon the second Tab key press, your shell prints the list of matching executables separated by 2 spaces, on the next line, and follow it with the prompt on a new line.
39
+
1. The first tab press rings the bell.
40
+
2. The second tab press displays all matching executables in alphabetical order.
41
+
- The matches are separated by two spaces.
42
+
- The matches are displayed on a new line.
43
+
3. The prompt reappears with the original input preserved.
0 commit comments