20
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

consul membersの結果でbash補完する

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
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
20
Help us understand the problem. What are the problem?