LoginSignup
58
63

More than 5 years have passed since last update.

aws-cliをタブキーで補完する

Last updated at Posted at 2015-01-13

aws-cli(AWS Command Line Interface)ではTabによるコマンド補完をサポートしてますが、デフォルトでは有効ではありません。

身の回りでcliを新しく触り始めた人が知らないケースがあったので、今回導入方法をまとめまてみました。
隣人が、長いコマンド名を手打ちしているのを見かけましたら、そっと教えてあげてください。

aws-cliはインストールしてある前提ですが、macだとこんな感じで簡単に入ります。

install
python --version # 2.6.3以降を確認
type pip # pipを確認 →なければインストールする
sudo -H pip install awscli # インストール

ちなみに更新するときはこうです

update
sudo -H pip install --upgrade awscli

windowsへのインストールや他のインストール方法についての詳細はこちらを参照してください。
http://docs.aws.amazon.com/cli/latest/userguide/installing.html

shellごとの設定

bash, zshでの設定方法です。

bash

aws_completerを探します。
多分、/usr/local/bin/usr/local/aws/binあたりにいると思います。
見つかったら、completeコマンドのoptionにパスを、argsにawsを指定してあげる感じです。
.bashrcに追加するのをお忘れなく。

command
type aws_completer # aws_completer is /usr/local/bin/aws_completer
complete -C '/usr/local/bin/aws_completer' aws
echo "complete -C '/usr/local/bin/aws_completer' aws" >> $HOME/.bashrc # if you want

zsh

zshの補完はaws_completerではなく、aws_zsh_completer.shを使います。
aws_zsh_completer.shをsourceコマンドで読み込んで上げればOKです。

command
type aws_zsh_completer.sh # aws_zsh_completer.sh is /usr/local/bin/aws_zsh_completer.sh
source /usr/local/bin/aws_zsh_completer.sh
echo "source /usr/local/bin/aws_zsh_completer.sh" >> $HOME/.zshrc # if you want

実行結果

こんな感じで補完されます。

長いコマンド名の打ち間違えを減らしたり、大量のコマンドを丸暗記しなくてもいいので、cliを使った作業効率が高まりますね。

aaa.gif

その他

cliをBundled Installerを使ってインストールした場合は、PATHを通す必要があるみたいです。(未検証)

path
export PATH=/usr/local/aws/bin:$PATH

参考

https://github.com/aws/aws-cli/blob/develop/README.rst#command-completion
http://docs.aws.amazon.com/cli/latest/userguide/cli-command-completion.html

追記

@ryo0301さんから編集リクエストいただきました、ありがとうございます。

awscliをインストールする為に、pipを実行するとログやキャッシュのパーミッションで警告がでることがあるらしいです。
その際は -H オプションをつけて実行してあげてください。

terminal
The directory '/Users/YOURNAME/Library/Logs/pip' or its parent directory is not owned by the current user and the debug log has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want the -H flag.
The directory '/Users/YOURNAME/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want the -H flag.
The directory '/Users/YOURNAME/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want the -H flag.
58
63
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
58
63