Skip to content

Commit eb4cfc3

Browse files
author
barry3406
committed
fix: drop shebang from bash completion template
Bash completion scripts are sourced, not executed, so they should not begin with a `#!/bin/bash` shebang. Debian's lintian flags this as `bash-completion-with-hashbang`. Add a regression test that renders the bash completion and asserts the output does not start with `#!`. Fixes #2259
1 parent bc00bd4 commit eb4cfc3

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

autocomplete/bash_autocomplete

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/bin/bash
2-
31
# This is a shell completion script auto-generated by https://github.com/urfave/cli for bash.
42

53
# Macs have bash3 for which the bash-completion package doesn't include

completion_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"strings"
78
"testing"
89

910
"github.com/stretchr/testify/assert"
@@ -63,6 +64,27 @@ func TestCompletionShell(t *testing.T) {
6364
}
6465
}
6566

67+
func TestCompletionBashNoShebang(t *testing.T) {
68+
// Regression test for https://github.com/urfave/cli/issues/2259
69+
// Bash completion scripts are sourced, not executed, so they must not
70+
// start with a `#!` shebang (flagged by Debian lintian as
71+
// `bash-completion-with-hashbang`).
72+
73+
cmd := &Command{
74+
EnableShellCompletion: true,
75+
}
76+
77+
r := require.New(t)
78+
79+
bashRender := shellCompletions["bash"]
80+
r.NotNil(bashRender, "bash completion renderer should exist")
81+
82+
output, err := bashRender(cmd, "myapp")
83+
r.NoError(err)
84+
r.NotEmpty(output, "bash completion output should not be empty")
85+
r.False(strings.HasPrefix(output, "#!"), "bash completion should not start with a shebang")
86+
}
87+
6688
func TestCompletionFishFormat(t *testing.T) {
6789
// Regression test for https://github.com/urfave/cli/issues/2285
6890
// Fish completion was broken due to incorrect format specifiers

0 commit comments

Comments
 (0)