LoginSignup
0
0

More than 1 year has passed since last update.

Go言語向けbash completionを使いたいという願望を叶える方法

Last updated at Posted at 2020-09-24

Go言語のコンパイラ、インタプリタ実行時にコマンドがTAB補完出来ず不便な思いをしていました。探したところ、gocompleteと言う拡張機能をインストールするとbash completionの様にTAB補完出来ることが分かりました。故に、利用方法を備忘録メモとして残しておこうと思います。

拡張機能の入手

$ go get -u github.com/posener/complete/gocomplete

2022/10/3更新

Go1.16.xからはgo installコマンドを用いるようになりました.(@バージョンを必ず付与。@latestで最新版をインストール)

go install github.com/posener/complete/v2/gocomplete@latest
実行結果
$ go install github.com/posener/complete/v2/gocomplete@latest
go: downloading github.com/posener/complete v1.2.3
go: downloading github.com/posener/complete/v2 v2.0.1-alpha.13
go: downloading github.com/hashicorp/go-multierror v1.0.0
go: downloading github.com/posener/script v1.1.5
go: downloading github.com/hashicorp/errwrap v1.0.0
  • 参考

インストール

$ $GOPATH/bin/gocomplete -install
Install completion for go? y
Installing...
Done!

2022/10/3更新

$ COMP_INSTALL=1 go/1.19.1/bin/gocomplete
install completion for go? y
installing...

上記のインストールコマンドの実行により、.bash_profileにgocompleteを有効化するための情報が書き込まれます。

.bash_profileに書き込まれる情報
complete -C /Users/user/go/bin/gocomplete go

2022/10/3更新

complete -C /Users/user/go/1.19.1/bin/gocomplete go

有効化

シェルを再起動するか、以下の様に.bash_profileを再読込すれば有効化されます。

$ source .bash_profile

Reference

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0