Skip to content

Commit 8cd114f

Browse files
authored
Merge pull request #38846 from windsonsea/bashmac
[zh] sync /included/optional-kubectl-configs-bash-mac.md
2 parents 484cf64 + a2388d9 commit 8cd114f

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

content/zh-cn/docs/tasks/tools/included/optional-kubectl-configs-bash-mac.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22
title: "macOS 系统上的 bash 自动补全"
33
description: "在 macOS 上实现 Bash 自动补全的一些可选配置。"
44
headless: true
5+
_build:
6+
list: never
7+
render: never
8+
publishResources: false
59
---
610
<!--
711
title: "bash auto-completion on macOS"
812
description: "Some optional configuration for bash auto-completion on macOS."
913
headless: true
10-
-->
14+
_build:
15+
list: never
16+
render: never
17+
publishResources: false
18+
-->
1119

1220
<!--
1321
### Introduction
@@ -20,7 +28,7 @@ The kubectl completion script for Bash can be generated with `kubectl completion
2028
However, the kubectl completion script depends on [**bash-completion**](https://github.com/scop/bash-completion) which you thus have to previously install.
2129
-->
2230
kubectl 的 Bash 补全脚本可以通过 `kubectl completion bash` 命令生成。
23-
在你的 shell 中导入(Sourcing)这个脚本即可启用补全功能。
31+
在你的 Shell 中导入(Sourcing)这个脚本即可启用补全功能。
2432

2533
此外,kubectl 补全脚本依赖于工具 [**bash-completion**](https://github.com/scop/bash-completion)
2634
所以你必须先安装它。
@@ -29,9 +37,9 @@ kubectl 的 Bash 补全脚本可以通过 `kubectl completion bash` 命令生成
2937
<!--
3038
There are two versions of bash-completion, v1 and v2. V1 is for Bash 3.2 (which is the default on macOS), and v2 is for Bash 4.1+. The kubectl completion script **doesn't work** correctly with bash-completion v1 and Bash 3.2. It requires **bash-completion v2** and **Bash 4.1+**. Thus, to be able to correctly use kubectl completion on macOS, you have to install and use Bash 4.1+ ([*instructions*](https://itnext.io/upgrading-bash-on-macos-7138bd1066ba)). The following instructions assume that you use Bash 4.1+ (that is, any Bash version of 4.1 or newer).
3139
-->
32-
bash-completion 有两个版本:v1 和 v2。v1 对应 Bash3.2(也是 macOS 的默认安装版本),v2 对应 Bash 4.1+。
40+
bash-completion 有两个版本:v1 和 v2。v1 对应 Bash 3.2(也是 macOS 的默认安装版本),v2 对应 Bash 4.1+。
3341
kubectl 的补全脚本**无法适配** bash-completion v1 和 Bash 3.2。
34-
必须为它配备 **bash-completion v2****Bash 4.1+**
42+
必须为它配备 **bash-completion v2****Bash 4.1+**
3543
有鉴于此,为了在 macOS 上使用 kubectl 补全功能,你必须要安装和使用 Bash 4.1+
3644
[**说明**](https://itnext.io/upgrading-bash-on-macos-7138bd1066ba))。
3745
后续说明假定你用的是 Bash 4.1+(也就是 Bash 4.1 或更新的版本)。
@@ -63,7 +71,7 @@ brew install bash
6371
<!--
6472
Reload your shell and verify that the desired version is being used:
6573
-->
66-
重新加载 shell,并验证所需的版本已经生效:
74+
重新加载 Shell,并验证所需的版本已经生效:
6775

6876
```bash
6977
echo $BASH_VERSION $SHELL
@@ -79,7 +87,6 @@ Homebrew 通常把它安装为 `/usr/local/bin/bash`。
7987
-->
8088
### 安装 bash-completion {#install-bash-completion}
8189

82-
8390
{{< note >}}
8491
<!--
8592
As mentioned, these instructions assume you use Bash 4.1+, which means you will install bash-completion v2 (in contrast to Bash 3.2 and bash-completion v1, in which case kubectl completion won't work).
@@ -104,14 +111,13 @@ As stated in the output of this command, add the following to your `~/.bash_prof
104111
如命令的输出信息所显示的,将如下内容添加到文件 `~/.bash_profile` 中:
105112

106113
```bash
107-
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
108-
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
114+
brew_etc="$(brew --prefix)/etc" && [[ -r "${brew_etc}/profile.d/bash_completion.sh" ]] && . "${brew_etc}/profile.d/bash_completion.sh"
109115
```
110116

111117
<!--
112118
Reload your shell and verify that bash-completion v2 is correctly installed with `type _init_completion`.
113119
-->
114-
重新加载 shell,并用命令 `type _init_completion` 验证 bash-completion v2 已经恰当的安装。
120+
重新加载 Shell,并用命令 `type _init_completion` 验证 bash-completion v2 已经恰当的安装。
115121

116122
<!--
117123
### Enable kubectl autocompletion
@@ -123,7 +129,7 @@ You now have to ensure that the kubectl completion script gets sourced in all yo
123129
124130
- Source the completion script in your `~/.bash_profile` file:
125131
-->
126-
你现在需要确保在所有的 shell 环境中均已导入(sourced) kubectl 的补全脚本,
132+
你现在需要确保在所有的 Shell 环境中均已导入(sourced)kubectl 的补全脚本,
127133
有若干种方法可以实现这一点:
128134

129135
- 在文件 `~/.bash_profile` 中导入(Source)补全脚本:
@@ -144,7 +150,7 @@ You now have to ensure that the kubectl completion script gets sourced in all yo
144150
<!--
145151
- If you have an alias for kubectl, you can extend shell completion to work with that alias:
146152
-->
147-
- 如果你为 kubectl 定义了别名,则可以扩展 shell 补全来兼容该别名:
153+
- 如果你为 kubectl 定义了别名,则可以扩展 Shell 补全来兼容该别名:
148154

149155
```bash
150156
echo 'alias k=kubectl' >>~/.bash_profile
@@ -154,21 +160,21 @@ You now have to ensure that the kubectl completion script gets sourced in all yo
154160
<!--
155161
- If you installed kubectl with Homebrew (as explained [here](/docs/tasks/tools/install-kubectl-macos/#install-with-homebrew-on-macos)), then the kubectl completion script should already be in `/usr/local/etc/bash_completion.d/kubectl`. In that case, you don't need to do anything.
156162
-->
157-
- 如果你是用 Homebrew 安装的 kubectl(如
158-
[此页面](/zh-cn/docs/tasks/tools/install-kubectl-macos/#install-with-homebrew-on-macos)所描述),
163+
- 如果你是用 Homebrew 安装的 kubectl
164+
(如[此页面](/zh-cn/docs/tasks/tools/install-kubectl-macos/#install-with-homebrew-on-macos)所描述),
159165
则 kubectl 补全脚本应该已经安装到目录 `/usr/local/etc/bash_completion.d/kubectl`
160166
中了。这种情况下,你什么都不需要做。
161167

162168
{{< note >}}
163169
<!--
164170
The Homebrew installation of bash-completion v2 sources all the files in the `BASH_COMPLETION_COMPAT_DIR` directory, that's why the latter two methods work.
165171
-->
166-
用 Hommbrew 安装的 bash-completion v2 会初始化 目录 `BASH_COMPLETION_COMPAT_DIR`
172+
用 Hommbrew 安装的 bash-completion v2 会初始化目录 `BASH_COMPLETION_COMPAT_DIR`
167173
中的所有文件,这就是后两种方法能正常工作的原因。
168174
{{< /note >}}
169175

170176
<!--
171177
In any case, after reloading your shell, kubectl completion should be working.
172178
-->
173-
总之,重新加载 shell 之后,kubectl 补全功能将立即生效。
179+
总之,重新加载 Shell 之后,kubectl 补全功能将立即生效。
174180

0 commit comments

Comments
 (0)