20
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

consul membersの結果でbash補完する

Last updated at Posted at 2015-02-24

consulでホストを管理してる状態で、bash-completionでのsshの補完候補にconsul membersの結果を使いたかったんです。個別にsshすると最近は若者にdisられるそうですが、それはそれこれはこれとして…

/etc/bash_completion_known_hosts_real の定義を以下のように置き換えるととりあえずできました。共通のを上書きしたくなければ個別に .bash_profile などで再定義すればよいですね。

_known_hosts_real()
{
     local members=$(consul members -status=alive | awk '!/Node/{printf("%s ", $1)}')
     COMPREPLY=( $( \
        compgen -W "$members" \
                ${COMP_WORDS[COMP_CWORD]} \
    ) )
    return 0
}
20
20
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
20
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?