Bash autocomplete not working
My urfave/cli version is
github.com/urfave/cli/v2 v2.27.5
Checklist
- [x] Are you running the latest v2 release? The list of releases is here.
- [x] Did you check the manual for your release? The v2 manual is here
- [x] Did you perform a search about this problem? Here's the GitHub guide about searching.
Dependency Management
- My project is using go modules.
- My project is using vendoring.
Describe the bug
A clear and concise description of what the bug is.
I built my application as specified in the documentation and use it as specified in https://cli.urfave.org/v2/examples/bash-completions/ However, when you press TAB on the command line with an incomplete sub-command name, nothing happens.
To reproduce
PROG=./out/bin/myprog source ./scripts/bash_autocomplete ./out/bin/myprog subcomm[press TAB]
Observed behavior
Nothing happens.
Expected behavior
bash auto-complete command in command-line to "subcommand".
Run go version and paste its output here
go version go1.23.2 linux/amd64
Run go env and paste its output here
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/user/projects/go/pkg/mod'
GOOS='linux'
GOPATH='/home/user/projects/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.2'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3090962808=/tmp/go-build -gno-record-gcc-switches'
@Aleksei-Badyaev Can you try PROG=myprog source ./scripts/bash_autocomplete ?
@Aleksei-Badyaev Can you try
PROG=myprog source ./scripts/bash_autocomplete?
I've already done that. I wrote above that I did everything exactly according to the documentation.
@Aleksei-Badyaev does the autocomplete work when you just press ./out/bin/myprog <TAB> without the subcommand ?
See https://github.com/urfave/cli/issues/1905 and https://github.com/urfave/cli/issues/1874
We plan on making shell completion easier to use in v3.
@Aleksei-Badyaev does the autocomplete work when you just press
./out/bin/myprog <TAB>without the subcommand ?
NO - nothing happens.
Hey Aleksei,
I have 3 simple Go CLI programs that are built with urfave/cli/v3 (not v2) and they support shell completion just fine. You might want to check them out as examples:
- https://github.com/bartekpacia/emu
- https://github.com/bartekpacia/fhome
If you're on mac, you can install them with Homebrew: e.g. brew install bartekpacia/tools/emu