# Stuck on Multiple completions #WH6

**URL:** <https://forum.codecrafters.io/t/stuck-on-multiple-completions-wh6/11200>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [May 26, 2025, 4:58pm UTC](https://forum.codecrafters.io/t/stuck-on-multiple-completions-wh6/11200 "2025-05-26T16:58:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![logan1o1](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/logan1o1/32/10383_2.png) [@logan1o1](https://forum.codecrafters.io/u/logan1o1)\
**Post date:** [May 26, 2025, 4:58pm UTC](https://forum.codecrafters.io/t/stuck-on-multiple-completions-wh6/11200/1 "2025-05-26T16:58:04Z")

</div>

I’m stuck on Stage Multiple completions #WH6

I’ve tried spliting the s to get the first $ xyz\_ only, but nothing worked.  
I don’t understand how to handle this problem, and you give me some tips.

GitHub repo: [https://github.com/logan1o1/codecrafters-shell-go](https://github.com/logan1o1/codecrafters-shell-go)

Here are my logs:

```auto
[tester::#WH6] Running ./your_program.sh
[tester::#WH6] ✓ Received prompt ($ )
[tester::#WH6] Typed "xyz_"
[your-program] $ xyz_
[tester::#WH6] ✓ Prompt line matches "$ xyz_"
[tester::#WH6] Pressed "<TAB>" (expecting bell to ring)
[tester::#WH6] Pressed "<TAB>" (expecting autocomplete to "xyz_bar xyz_baz xyz_quz")
[tester::#WH6] Output does not match expected value.
[tester::#WH6] Expected: "$ xyz_"
[tester::#WH6] Received: "$ xyz_$ xyz_"
[tester::#WH6] Assertion failed.
[tester::#WH6] Test failed

```

And here’s a snippet of my code:

```go
rl, err := readline.NewEx(&readline.Config{
		Prompt: "$ ",
		// AutoComplete: completer,
		InterruptPrompt: "^C",
		EOFPrompt: "exit",
	})
	if err != nil {
		fmt.Println(err)
	}

	rl.CaptureExitSignal()
	defer rl.Close()

	cachedExe := CustomExeFromPath()

	var lastPrefix string
	var tabCount int

	completer := readline.NewPrefixCompleter(
		readline.PcItem("echo"),
		readline.PcItem("exit"),
		readline.PcItemDynamic(func(s string) []string {

			if s != lastPrefix {
				lastPrefix = s
				tabCount = 0
			}
			tabCount++

			var match []string
			for _, cxe := range cachedExe {
				if strings.HasPrefix(cxe, s) {
					// fmt.Print("\a")
					match = append(match, cxe)
				}
			}
			sort.Strings(match)

			if len(match) == 0 {
				rl.Write([]byte("\a"))
				return nil
			}

			if len(match) == 1 {
				return match
			}

			if tabCount == 1 {
				rl.Write([]byte("\a"))
				return nil
			}

			fmt.Printf("$ %s\n", s)
			tabCount = 0
			return nil
		}),
	)

	rl.Config.AutoComplete = completer

```

---

<div class="post-metadata">

**Author:** ![logan1o1](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/logan1o1/32/10383_2.png) [@logan1o1](https://forum.codecrafters.io/u/logan1o1)\
**Post date:** [May 27, 2025, 6:03am UTC](https://forum.codecrafters.io/t/stuck-on-multiple-completions-wh6/11200/4 "2025-05-27T06:03:38Z")

</div>

completed

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [June 1, 2025, 7:07pm UTC](https://forum.codecrafters.io/t/stuck-on-multiple-completions-wh6/11200/6 "2025-06-01T19:07:12Z")

</div>

Closed on June 1, 2025, 7:07pm UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
