diff --git a/autocomplete/bash_autocomplete b/autocomplete/bash_autocomplete index 987314422a..cf9c20f31b 100755 --- a/autocomplete/bash_autocomplete +++ b/autocomplete/bash_autocomplete @@ -1,5 +1,3 @@ -#!/bin/bash - # This is a shell completion script auto-generated by https://github.com/urfave/cli for bash. # Macs have bash3 for which the bash-completion package doesn't include diff --git a/completion_test.go b/completion_test.go index b53e4b90f8..d0c5e684c9 100644 --- a/completion_test.go +++ b/completion_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -63,6 +64,27 @@ func TestCompletionShell(t *testing.T) { } } +func TestCompletionBashNoShebang(t *testing.T) { + // Regression test for https://github.com/urfave/cli/issues/2259 + // Bash completion scripts are sourced, not executed, so they must not + // start with a `#!` shebang (flagged by Debian lintian as + // `bash-completion-with-hashbang`). + + cmd := &Command{ + EnableShellCompletion: true, + } + + r := require.New(t) + + bashRender := shellCompletions["bash"] + r.NotNil(bashRender, "bash completion renderer should exist") + + output, err := bashRender(cmd, "myapp") + r.NoError(err) + r.NotEmpty(output, "bash completion output should not be empty") + r.False(strings.HasPrefix(output, "#!"), "bash completion should not start with a shebang") +} + func TestCompletionFishFormat(t *testing.T) { // Regression test for https://github.com/urfave/cli/issues/2285 // Fish completion was broken due to incorrect format specifiers