はじめに
WSL2 も使えるいまの時代にどれほどの需要があるのか疑問ですが、Git Bash にも bash-completion を導入する方法をメモとして残します。
なお、パッケージマネージャーには Scoop を利用します。適宜 Chocolatey や Windows パッケージ マネージャー などに読み替えてください。
make のインストール
bash
$ scoop install make
Updating Scoop...
Scoop was updated successfully!
Installing 'make' (4.3) [64bit]
make-4.3-without-guile-w32-bin.zip (353.0 KB) [===============================================================] 100%
Checking hash of make-4.3-without-guile-w32-bin.zip ... ok.
Extracting make-4.3-without-guile-w32-bin.zip ... done.
Linking ~\scoop\apps\make\current => ~\scoop\apps\make\4.3
Creating shim for 'make'.
'make' (4.3) was installed successfully!
$ which make
/c/Users/qiita/scoop/shims/make
bash-completion のソースコードをダウンロード
bash-completion リポジトリのリリースページから最新の bash-completion-x.x.x.tar.xz を任意の場所へダウンロードします。
bash-completion のビルドとインストール
1. ソースコードの展開
bash-completion-x.x.x.tar.xz を置いたディレクトリへ移動し、tar.xz を展開します。
bash
$ xz -dv bash-completion-2.11.tar.xz
bash-completion-2.11.tar.xz (1/1)
100 % 303.7 KiB / 2,862.5 KiB = 0.106
$ tar xvf bash-completion-2.11.tar
bash-completion-2.11/
bash-completion-2.11/AUTHORS
bash-completion-2.11/install-sh
bash-completion-2.11/bash-completion.pc.in
bash-completion-2.11/CHANGES
~ 中略 ~
bash-completion-2.11/configure.ac
xz と tar コマンドはともに Git Bash に同梱されてインストール済みです。
2. configure スクリプトの実行
展開したソースコードのディレクトリへ入り、configure スクリプトを実行して Makefile を作成します。
bash
$ cd bash-completion-2.11
$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether ln -s works... no, using cp -pR
checking for a sed that does not truncate output... /usr/bin/sed
checking for pytest... no
checking for pytest-3... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating completions/Makefile
config.status: creating doc/Makefile
config.status: creating helpers/Makefile
config.status: creating test/Makefile
config.status: creating test/t/Makefile
config.status: creating test/t/unit/Makefile
3. ビルド&インストール
とくに問題が発生していないなら、そのままビルドとインストールを実行します。
ビルド
bash
$ make
Making all in completions
make[1]: Entering directory 'C:/Users/qiita/Downloads/bash-completion-2.11/completions'
~ 中略 ~
/usr/bin/sed \
-e 's|@prefix[@]|/usr/local|' \
-e 's|@datadir[@]|/usr/local/share|' \
-e 's|@sysconfdir[@]|/usr/local/etc|' \
-e 's|@PACKAGE[@]|bash-completion|' \
-e 's|@VERSION[@]|2.11|' \
<./bash_completion.sh.in >bash_completion.sh
make[1]: Leaving directory 'C:/Users/qiita/Downloads/bash-completion-2.11'
インストール
bash
$ make install
Making install in completions
make[1]: Entering directory 'C:/Users/qiita/Downloads/bash-completion-2.11/completions'
./../setup-symlinks.sh . 7z \
7za
~ 中略 ~
/usr/bin/sed -e 's|-/etc/bash_completion\.d|-/usr/local/etc/bash_completion.d|' \
/usr/local/share/bash-completion/bash_completion >$tmpfile && \
cat $tmpfile >/usr/local/share/bash-completion/bash_completion && \
rm $tmpfile
make[3]: Leaving directory 'C:/Users/qiita/Downloads/bash-completion-2.11'
make[2]: Leaving directory 'C:/Users/qiita/Downloads/bash-completion-2.11'
make[1]: Leaving directory 'C:/Users/qiita/Downloads/bash-completion-2.11'
/usr/local/share 以下(Windows 上での実体パスは %USERPROFILE%\scoop\apps\git\2.32.0.windows.2\usr\local\share)へインストールされたことが確認できると思います。
.bashrc へ追加
Bash の設定ファイル $HOME/.bashrc(または .bash_profile など)へ以下を追記します。
~/.bashrc
[[ $PS1 && -f /usr/local/share/bash-completion/bash_completion ]] && \
. /usr/local/share/bash-completion/bash_completion
ログインし直すか、設定ファイルを読み込めば完了です。
bash
$ source ~/.bashrc
↧