|
1 | 1 | --- |
2 | | -title: "bash auto-completion on macOS" |
3 | | -description: "Some optional configuration for bash auto-completion on macOS." |
| 2 | +title: "macOS上でのbashの自動補完" |
| 3 | +description: "macOS上でのbashの自動補完に対するいくつかの補助的な設定。" |
4 | 4 | headless: true |
5 | 5 | _build: |
6 | 6 | list: never |
7 | 7 | render: never |
8 | 8 | publishResources: false |
9 | 9 | --- |
10 | 10 |
|
11 | | -### Introduction |
| 11 | +### はじめに |
12 | 12 |
|
13 | | -The kubectl completion script for Bash can be generated with `kubectl completion bash`. |
14 | | -Sourcing this script in your shell enables kubectl completion. |
| 13 | +Bashにおけるkubectlの補完スクリプトは`kubectl completion bash`コマンドで生成できます。 |
| 14 | +シェル内で補完スクリプトをsourceすることでkubectlの自動補完が有効になります。 |
15 | 15 |
|
16 | | -However, the kubectl completion script depends on |
17 | | -[**bash-completion**](https://github.com/scop/bash-completion) which you thus have to previously install. |
| 16 | +ただし、補完スクリプトは[**bash-completion**](https://github.com/scop/bash-completion)に依存しているため、事前にインストールしておく必要があります。 |
18 | 17 |
|
19 | 18 | {{< warning>}} |
20 | | -There are two versions of bash-completion, v1 and v2. V1 is for Bash 3.2 |
21 | | -(which is the default on macOS), and v2 is for Bash 4.1+. The kubectl completion |
22 | | -script **doesn't work** correctly with bash-completion v1 and Bash 3.2. |
23 | | -It requires **bash-completion v2** and **Bash 4.1+**. Thus, to be able to |
24 | | -correctly use kubectl completion on macOS, you have to install and use |
25 | | -Bash 4.1+ ([*instructions*](https://itnext.io/upgrading-bash-on-macos-7138bd1066ba)). |
26 | | -The following instructions assume that you use Bash 4.1+ |
27 | | -(that is, any Bash version of 4.1 or newer). |
| 19 | +bash-completionにはv1とv2の2つのバージョンがあります。 |
| 20 | +v1はBash 3.2(macOSのデフォルト)用で、v2はBash 4.1以降向けです。 |
| 21 | +kubectlの補完スクリプトはbash-completionのv1とBash 3.2では正しく**動作しません**。 |
| 22 | +**bash-completion v2**と**Bash 4.1以降**が必要になります。 |
| 23 | +したがって、macOSで正常にkubectlの補完を使用するには、Bash 4.1以降をインストールする必要があります([*手順*](https://itnext.io/upgrading-bash-on-macos-7138bd1066ba))。 |
| 24 | +以下の手順では、Bash4.1以降(Bashのバージョンが4.1またはそれより新しいことを指します)を使用することを前提とします。 |
28 | 25 | {{< /warning >}} |
29 | 26 |
|
30 | | -### Upgrade Bash |
| 27 | +### Bashのアップグレード |
31 | 28 |
|
32 | | -The instructions here assume you use Bash 4.1+. You can check your Bash's version by running: |
| 29 | +ここではBash 4.1以降の使用を前提としています。 |
| 30 | +Bashのバージョンは下記のコマンドで調べることができます: |
33 | 31 |
|
34 | 32 | ```bash |
35 | 33 | echo $BASH_VERSION |
36 | 34 | ``` |
37 | 35 |
|
38 | | -If it is too old, you can install/upgrade it using Homebrew: |
| 36 | +バージョンが古い場合、Homebrewを使用してインストールもしくはアップグレードできます: |
39 | 37 |
|
40 | 38 | ```bash |
41 | 39 | brew install bash |
42 | 40 | ``` |
43 | 41 |
|
44 | | -Reload your shell and verify that the desired version is being used: |
| 42 | +シェルをリロードし、希望するバージョンを使用していることを確認してください: |
45 | 43 |
|
46 | 44 | ```bash |
47 | 45 | echo $BASH_VERSION $SHELL |
48 | 46 | ``` |
49 | 47 |
|
50 | | -Homebrew usually installs it at `/usr/local/bin/bash`. |
| 48 | +Homebrewは通常、`/usr/local/bin/bash`にインストールします。 |
51 | 49 |
|
52 | | -### Install bash-completion |
| 50 | +### bash-completionをインストールする |
53 | 51 |
|
54 | 52 | {{< note >}} |
55 | | -As mentioned, these instructions assume you use Bash 4.1+, which means you will |
56 | | -install bash-completion v2 (in contrast to Bash 3.2 and bash-completion v1, |
57 | | -in which case kubectl completion won't work). |
| 53 | +前述のとおり、この手順ではBash 4.1以降であることが前提のため、bash-completion v2をインストールすることになります(これとは逆に、Bash 3.2およびbash-completion v1の場合ではkubectlの補完は動作しません)。 |
58 | 54 | {{< /note >}} |
59 | 55 |
|
60 | | -You can test if you have bash-completion v2 already installed with `type _init_completion`. |
61 | | -If not, you can install it with Homebrew: |
| 56 | + |
| 57 | +`type _init_completion`を実行することで、bash-completionがすでにインストールされていることを確認できます。 |
| 58 | +ない場合は、Homebrewを使用してインストールすることができます: |
62 | 59 |
|
63 | 60 | ```bash |
64 | 61 | brew install bash-completion@2 |
65 | 62 | ``` |
66 | 63 |
|
67 | | -As stated in the output of this command, add the following to your `~/.bash_profile` file: |
| 64 | +このコマンドの出力で示されたように、`~/.bash_profile`に以下を追記してください: |
68 | 65 |
|
69 | 66 | ```bash |
70 | 67 | brew_etc="$(brew --prefix)/etc" && [[ -r "${brew_etc}/profile.d/bash_completion.sh" ]] && . "${brew_etc}/profile.d/bash_completion.sh" |
71 | 68 | ``` |
72 | 69 |
|
73 | | -Reload your shell and verify that bash-completion v2 is correctly installed with `type _init_completion`. |
| 70 | +シェルをリロードし、`type _init_completion`を実行してbash-completion v2が正しくインストールされていることを検証してください。 |
74 | 71 |
|
75 | | -### Enable kubectl autocompletion |
| 72 | +### kubectlの自動補完を有効にする |
76 | 73 |
|
77 | | -You now have to ensure that the kubectl completion script gets sourced in all |
78 | | -your shell sessions. There are multiple ways to achieve this: |
| 74 | +すべてのシェルセッションにてkubectlの補完スクリプトをsourceできるようにしなければなりません。 |
| 75 | +これを行うには複数の方法があります: |
79 | 76 |
|
80 | | -- Source the completion script in your `~/.bash_profile` file: |
| 77 | +- 補完スクリプトを`~/.bash_profile`内でsourceする: |
81 | 78 |
|
82 | 79 | ```bash |
83 | 80 | echo 'source <(kubectl completion bash)' >>~/.bash_profile |
84 | 81 | ``` |
85 | 82 |
|
86 | | -- Add the completion script to the `/usr/local/etc/bash_completion.d` directory: |
| 83 | +- 補完スクリプトを`/usr/local/etc/bash_completion.d`ディレクトリに追加する: |
87 | 84 |
|
88 | 85 | ```bash |
89 | 86 | kubectl completion bash >/usr/local/etc/bash_completion.d/kubectl |
90 | 87 | ``` |
91 | 88 |
|
92 | | -- If you have an alias for kubectl, you can extend shell completion to work with that alias: |
| 89 | +- kubectlにエイリアスを張っている場合は、エイリアスでも動作するようにシェルの補完を拡張することができます: |
93 | 90 |
|
94 | 91 | ```bash |
95 | 92 | echo 'alias k=kubectl' >>~/.bash_profile |
96 | 93 | echo 'complete -o default -F __start_kubectl k' >>~/.bash_profile |
97 | 94 | ``` |
98 | 95 |
|
99 | | -- If you installed kubectl with Homebrew (as explained |
100 | | - [here](/docs/tasks/tools/install-kubectl-macos/#install-with-homebrew-on-macos)), |
101 | | - then the kubectl completion script should already be in `/usr/local/etc/bash_completion.d/kubectl`. |
102 | | - In that case, you don't need to do anything. |
| 96 | +- kubectlをHomebrewでインストールした場合([前述](/ja/docs/tasks/tools/install-kubectl-macos/#install-with-homebrew-on-macos)の通り)、kubectlの補完スクリプトはすでに`/usr/local/etc/bash_completion.d/kubectl`に格納されているでしょうか。 |
| 97 | + この場合、なにも操作する必要はありません。 |
103 | 98 |
|
104 | 99 | {{< note >}} |
105 | | - The Homebrew installation of bash-completion v2 sources all the files in the |
106 | | - `BASH_COMPLETION_COMPAT_DIR` directory, that's why the latter two methods work. |
| 100 | + Homebrewでインストールしたbash-completion v2は`BASH_COMPLETION_COMPAT_DIR`ディレクトリ内のすべてのファイルをsourceするため、後者の2つの方法が機能します。 |
107 | 101 | {{< /note >}} |
108 | 102 |
|
109 | | -In any case, after reloading your shell, kubectl completion should be working. |
| 103 | +どの場合でも、シェルをリロードしたあとに、kubectlの自動補完が機能するはずです。 |
0 commit comments