Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions cli/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"io"
"os"
"path/filepath"
"strings"
)

Expand Down Expand Up @@ -44,15 +46,19 @@ func (a *App) handleCompletionScript(args []string) int {
)
return 1
}
// Use the actual binary name so the completion script matches
// whatever name the binary was installed as.
binName := filepath.Base(os.Args[0])

// Completion scripts and __complete output go to stdout, not
// a.output (which defaults to stderr). The shell reads stdout.
switch args[0] {
case "bash":
writeBashCompletion(a.stdout, a.name)
writeBashCompletion(a.stdout, binName)
case "zsh":
writeZshCompletion(a.stdout, a.name)
writeZshCompletion(a.stdout, binName)
case "fish":
writeFishCompletion(a.stdout, a.name)
writeFishCompletion(a.stdout, binName)
default:
fmt.Fprintf(
a.output,
Expand Down
4 changes: 3 additions & 1 deletion cli/complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ func TestCompletionScripts(t *testing.T) {

output := buf.String()
require.NotEmpty(t, output)
assert.Contains(t, output, "testapp")
// The script should reference the actual binary name,
// not the app's logical name.
assert.NotContains(t, output, "testapp")
})
}
}
Expand Down
Loading