LoginSignup
5
0

More than 5 years have passed since last update.

【zsh】g=git, d=docker,k=kubectlのような一文字aliasに補完をキかせる

Last updated at Posted at 2019-04-24

はじめに

今まで$ git$ g , $ docker$ d といったように1文字aliasを登録していた。

また、zshの補完を強くするためにzsh-users/zsh-completions等を用いていた。

だがaliasにより縮めたコマンドにはzshの補完や、上記プラグインの補完が効かなかったので補完をきかせるようにした。

.zshrc
alias g='git'
compdef g=git
alias d='docker'
compdef d=docker
alias fig='docker-compose'
compdef fig=docker-compose
alias k='kubectl'
compdef k=kubectl

dotfiles/.aliases.sh at 0a380bee3f3eac14d14a6295a862d42d838efefc · 2357gi/dotfiles

ちなみにcompdefにて登録すればalias g='git'を記述する必要はない。
訂正: そんなことはなかった。失礼しました。

ちなみに.gitconfigに記載したaliasの設定もこれで拾ってくれます。好き。
dotfiles/.gitconfig.local.template at master · 2357gi/dotfiles

おまけ 各種補完

railsとかdockerとかgitとか幅広くいろいろ補完してくれるやつ

冒頭でも言及したやつ

$ brew install zsh-completions
.zshrc
+ fpath=(/path/to/homebrew/share/zsh-completions $fpath)

+ autoload -U compinit
+ compinit -u
# 既に記述がある場合は適宜調整してね

docker-composeの補完

$ mkdir -p ~/.zsh/completion
$ curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/zsh/_docker-compose > ~/.zsh/completion/_docker-compose
.zshrc
 ︙

+ fpath=(~/.zsh/completion $fpath)

kubectlの補完

.zshrc
+ source <(kubectl completion zsh)

これ中身おもろいです。
kubectl completion zshで標準出力なので中身覗いてみてください

5
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
5
0