终端 > 终端外观
终端提示符
# 终端提示符 import DemoVideo from '@components/DemoVideo.astro'; import VideoEmbed from '@components/VideoEmbed.astro'; Warp 支持两种提示符类型:**Warp 提示符**和 **Shell 提示符 (PS1)**。 ## 选择您的提示符类型 要切换提示符类型: 1. 打开 **Settings**(设置)> **Appearance**(外观)。 2. 在 **Input**(输入)下,将 **Input type**(输入类型)设置为 **Warp** 或 **Shell (PS1)**。 当使用 Warp 提示符时,您可以右键点击提示符区域以复制整个提示符、当前工作目录、当前 git 分支、git 未提交文件计数等。 当使用 Shell 提示符时,您可以右键点击提示符区域以复制整个提示符,或在会话中之前运行的块中选择提示符的任何部分。 ## Warp 提示符 Warp 拥有一个原生提示符,它显示上下文芯片,展示诸如当前工作目录、git 分支、svn 状态、Kubernetes 上下文、pyenv、日期和时间等信息。当 **Input type** 设置为 **Warp** 时,Warp 提示符为默认设置。 要自定义 Warp 提示符显示的上下文芯片: 1. 右键点击提示符区域并选择 **Edit prompt**(编辑提示符)。 <figure>  <figcaption>通过右键点击进行提示符编辑。</figcaption> </figure> 2. 选择 **Warp Prompt**。 3. 拖放上下文芯片以配置您的提示符显示哪些信息。 {/* TODO: 在此处添加更新后的“编辑提示符”芯片自定义视图(拖放界面)截图,并从 assets 中删除过时的 edit-prompt-modal (1).png。 */} ### Git 和 Subversion Git 和 Subversion 上下文芯片显示您当前所在的本地分支,以及未提交的已更改文件数量。这包括任何已暂存或未暂存的新文件、修改过的文件和已删除的文件。 ### Kubernetes 当您使用以下命令之一时,Kubernetes 上下文芯片会显示相关信息: `kubectl|helm|kubens|kubectx|oc|istioctl|kogito|k9s|helmfile|flux|fluxctl|stern|kubeseal|skaffold|kubent|kubecolor|cmctl|sparkctl|etcd|fubectl` :::note Warp 尊重 `KUBECONFIG` 环境变量。如果它不是 `~/.kube/config` 的默认路径,请确保将其设置为您首选的配置文件位置。 ::: {/* TODO: 同行提示符在当前版本中已被移除。可能会在未来版本(V2/V3)中回归。当该功能发布时请取消注释。 */} {/* ### 同行提示符 默认情况下,Warp 的提示符显示在两行上,其中命令行输入在提示符下方的一行。要启用同行提示符: 1. 右键点击提示符区域并选择 **Edit prompt**。 2. 选择 **Warp Prompt**。 3. 勾选 **Same line prompt**(同行提示符)复选框。 */} ## Shell 提示符 (PS1) 您可以通过配置 **PS1** 变量或安装受支持的 Shell 提示符插件来使用 Shell 提示符代替 Warp 提示符(请参阅 [Shell 提示符兼容性表](/terminal/appearance/prompt/#shell-prompt-compatibility-table))。 要启用 Shell 提示符: 1. 打开 **Settings** > **Appearance**。 2. 在 **Input** 下,将 **Input type** 设置为 **Shell (PS1)**。 3. 在您的 Shell 的 RC 文件中配置 PS1 变量,或安装受支持的提示符插件。 :::note PS1 是 Shell 用来生成提示符的变量,它代表主提示符字符串(因此得名“PS”)——终端通常在输入新命令之前显示它。 ::: ### 多行和右侧提示符 Shell 提示符在 zsh 和 fish 中支持多行或右侧提示符,但在 bash 中不支持。但是,您不能拥有多行右侧提示符,只能拥有多行左侧提示符。 :::note 如果您想在 Shell 提示符中添加新行,请根据您的 Shell 或提示符运行以下命令: ```sh # Bash echo -e '\nPS1="${PS1}"$'\''\\n'\''' >> ~/.bashrc # Zsh echo -e '\nPROMPT="${PROMPT}"$'\''\\n'\''' >> ~/.zshrc # Fish echo -e '\nfunctions --copy fish_prompt fish_prompt_orig; function fish_prompt; fish_prompt_orig; echo; end' >> ~/.config/fish/config.fish # Powershell $rawString = @' $originalPrompt = Get-Item Function:\prompt Set-Item -Path Function:\prompt_original -Value $originalPrompt function prompt { "$(& prompt_original)`n" } '@ Add-Content -Path $PROFILE -Value "`n$rawString`n" # Powerlevel10k p10k configure # Starship 提示符 echo '[line_break]\ndisabled = false' >> ~/.config/starship.toml ``` ::: ## 其工作原理 <DemoVideo src="/assets/terminal/warp-custom-prompt-demo.mp4" label="Warp 提示符 + 自定义提示符演示" /> {/* 已移除过时的截图;请参阅 Warp 提示符部分第 3 步之后的 TODO。 */} ### Shell 提示符兼容性表 | Shell | 工具 | 是否有效? | | --------------------------- | ------------------------------------------------------------------------- | --------------------------------------------------------------- | | bash | zsh | [PS1](https://warp.org.cn/blog/whats-so-special-about-ps1) | 有效 | | bash | zsh | fish | pwsh | [Starship](https://github.com/starship/starship) | [有效\*](/terminal/appearance/prompt/#starship) | | bash | zsh | fish | pwsh | [oh-my-posh](https://github.com/JanDeDobbeleer/oh-my-posh) | 有效 | | zsh | [Powerlevel10k](https://github.com/romkatv/powerlevel10k) | [有效\*](/terminal/appearance/prompt/#powerlevel10k) | | zsh | [Spaceship](https://github.com/spaceship-prompt/spaceship-prompt) | [有效\*](/terminal/appearance/prompt/#spaceship) | | zsh | [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh) | 有效 | | zsh | [prezto](https://github.com/sorin-ionescu/prezto) | [有效\*](/terminal/appearance/prompt/#prezto) | | ssh | | 有效 | | bash | [oh-my-bash](https://github.com/ohmybash/oh-my-bash) | 不支持 | | bash | [bash-it](https://github.com/Bash-it/bash-it) | 不支持 | | bash | [SBP](https://github.com/brujoand/sbp) | 不支持 | | bash | [synth-shell-prompt](https://github.com/andresgongora/synth-shell-prompt) | 不支持 | | bash | zsh | [Powerline-shell](https://github.com/b-ryan/powerline-shell) | 不支持 | | zsh | [zplug](https://github.com/zplug/zplug) | 不支持 | | fish | [tide](https://github.com/IlanCosman/tide) | [不支持](https://github.com/warpdotdev/Warp/issues/3358) | | fish | [oh-my-fish](https://github.com/oh-my-fish/oh-my-fish) | [不支持](https://github.com/warpdotdev/Warp/issues/3796) | ## 已知不兼容情况 如果您在使用提示符时遇到问题,请查看下文或我们的 [已知问题](/support-and-community/troubleshooting-and-support/known-issues/#configuring-and-debugging-your-rc-files) 以获取更多故障排除步骤。 ### Starship #### Starship 设置 已知某些 `~/.config/starship.toml` 设置会导致 Warp 出错。使用 `#` 或 `DEL` 处理以下行以解决已知错误: ``` # 根据配置模式获取编辑器补全 '' = 'https://starship.rs/config-schema.json' # 禁用自定义模块 [custom] disabled = false ``` 对于 `fish` Shell(`bash|zsh` 可选),通过在您的 `~/.config/starship.toml` 中放入以下内容来禁用 Starship 中的多行提示符: ``` [line_break] disabled = true ``` 您可能还会看到与超时相关的错误。您可以在 `~/.config/starship.toml` 中设置 `command_timeout` 变量来修复此问题。更多信息请参见 [starship 文档](https://starship.rs/config/#prompt)。 #### Starship + bash 如果您的 [默认 Shell](/getting-started/supported-shells/#changing-what-shell-warp-uses) 是 `/bin/bash`,Starship 提示符可能无法正确渲染。要 [绕过](https://github.com/warpdotdev/Warp/issues/3066#issuecomment-1548643121) 该问题,我们建议您升级 bash,通过 `echo $(which bash)` 找到路径,然后将该路径放入 **Settings** > **Features** > **Session** > **“Startup shell for new sessions”**。 #### Starship + zsh 如果您想在 `zsh` 上恢复 Starship 提示符后的附加行,请将以下内容添加到您的 `~/.zshrc` 文件末尾: `PROMPT="${PROMPT}"$'\n'` ### Powerlevel10k 安装 Powerlevel10k (P10k) 提示符时,我们建议您使用 [Meslo Nerd Font](https://github.com/romkatv/powerlevel10k/blob/master/font.md)。 P10K 可能会将箭头分隔符显示为灰色而不是彩色。这些字符的颜色由于 Warp 的最小对比度设置而被渲染为灰色。要 [绕过](https://github.com/warpdotdev/Warp/issues/2851#issuecomment-1605005256) 此问题,请转到 **Settings** > **Appearance** > **Text** > **Enforce minimum contrast** 并将其设置为“Never”。 <figure>  <figcaption>p10k 中灰色分隔符的示例。</figcaption> </figure> Warp 确实支持 [p10k](https://github.com/romkatv/powerlevel10k#installation) 1.19.0 及更高版本。确保您已安装最新版本,并在安装/更新 p10k 后重启 Warp。然后按 [上述](/terminal/appearance/prompt/#choosing-your-prompt-type) 说明启用自定义提示符,它应该可以正常工作。 :::note Warp 仍未完全支持某些 p10k 功能,如瞬态提示符和视觉功能(如渐变)。 ::: <VideoEmbed url="https://www.youtube.com/watch?t=18s&v=dIV9Cso4Mi8" title="安装 Powerlevel10k" /> :::caution 请注意,“安装 Powerlevel10k”视频提到了在 **Settings** > **Features** > **Honor users custom prompt (PS1)** 中启用自定义提示符,但现在它位于 **Settings** > **Appearance** > **Input** > **Classic** > **Current prompt** > **Shell Prompt (PS1)** 中。 ::: ### Spaceship 此提示符可能会导致 Warp 输入编辑器中的预输入出现问题。要 [绕过](https://github.com/warpdotdev/Warp/issues/1973#issuecomment-1340150521) 该问题,请运行 `echo "SPACESHIP_PROMPT_ASYNC=FALSE" >>! ~/.zshrc`。 ### Prezto 尽管 Warp 对 prezto 的提示符有支持,但在 `.zpreztorc` 中启用 [prezto 实用程序模块](https://github.com/sorin-ionescu/prezto/blob/master/modules/utility/README.md) 是不受支持的,就像许多其他不兼容的自动补全 [插件一样](/support-and-community/troubleshooting-and-support/known-issues/#list-of-incompatible-tools)。 ### 为 Warp 禁用不支持的提示符 我们建议使用 Warp 的默认提示符或安装受支持的工具之一,请参阅 [兼容性表](/terminal/appearance/prompt/#shell-prompt-compatibility-table)。您可以为 Warp 禁用不支持的提示符,如下所示: ``` if [[ $TERM_PROGRAM != "WarpTerminal" ]]; then ##### 您想要为 WARP 禁用的内容 - 下方 # 不受支持的自定义提示符代码 ##### 您想要为 WARP 禁用的内容 - 上方 fi ``` #### iTerm2 iTerm2 Shell 集成会破坏 Warp,启用此功能后,您的自定义提示符将无法显示。如果您来自 iTerm2,请检查您的 dotfiles。我们建议为 Warp 禁用此集成,如下所示: ``` if [[ $TERM_PROGRAM != "WarpTerminal" ]]; then ##### 您想要为 WARP 禁用的内容 - 下方 test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh" ##### 您想要为 WARP 禁用的内容 - 上方 fi ```使用上下文芯片配置 Warp 的原生提示符,或使用您自己的 Shell 提示符 (PS1)。
Warp 支持两种提示符类型:Warp 提示符和 Shell 提示符 (PS1)。
选择提示符类型
题为“选择提示符类型”的章节要切换提示符类型
- 打开 Settings(设置)> Appearance(外观)。
- 在 Input(输入)下,将 Input type(输入类型)设置为 Warp 或 Shell (PS1)。
当使用 Warp 提示符时,您可以右键点击提示符区域以复制整个提示符、当前工作目录、当前 git 分支、git 未提交文件计数等。
当使用 Shell 提示符时,您可以右键点击提示符区域以复制整个提示符,或在会话中之前运行的块中选择提示符的任何部分。
Warp 提示符
题为“Warp 提示符”的章节Warp 拥有一个原生提示符,它显示上下文芯片,展示诸如当前工作目录、git 分支、svn 状态、Kubernetes 上下文、pyenv、日期和时间等信息。当 Input type 设置为 Warp 时,Warp 提示符为默认设置。
要自定义 Warp 提示符显示的上下文芯片
- 右键点击提示符区域并选择 Edit prompt(编辑提示符)。
- 选择 Warp Prompt。
- 拖放上下文芯片以配置您的提示符显示哪些信息。
Git 和 Subversion
题为“Git 和 Subversion”的章节Git 和 Subversion 上下文芯片显示您当前所在的本地分支,以及未提交的已更改文件数量。这包括任何已暂存或未暂存的新文件、修改过的文件和已删除的文件。
Kubernetes
题为“Kubernetes”的章节当您使用以下命令之一时,Kubernetes 上下文芯片会显示相关信息
kubectl|helm|kubens|kubectx|oc|istioctl|kogito|k9s|helmfile|flux|fluxctl|stern|kubeseal|skaffold|kubent|kubecolor|cmctl|sparkctl|etcd|fubectl
Shell 提示符 (PS1)
题为“Shell 提示符 (PS1)”的章节您可以通过配置 PS1 变量或安装受支持的 Shell 提示符插件来使用 Shell 提示符代替 Warp 提示符(请参阅 Shell 提示符兼容性表)。
要启用 Shell 提示符
- 打开 Settings(设置)> Appearance(外观)。
- 在 Input(输入)下,将 Input type(输入类型)设置为 Shell (PS1)。
- 在您的 Shell 的 RC 文件中配置 PS1 变量,或安装受支持的提示符插件。
多行和右侧提示符
题为“多行和右侧提示符”的章节Shell 提示符在 zsh 和 fish 中支持多行或右侧提示符,但在 bash 中不支持。但是,您不能拥有多行右侧提示符,只能拥有多行左侧提示符。
工作原理
标题为“工作原理”的章节Shell 提示符兼容性表
题为“Shell 提示符兼容性表”的章节| Shell | 工具 | 是否有效? |
|---|---|---|
| bash | zsh | PS1 | 有效 |
| bash | zsh | fish | pwsh | Starship | 有效* |
| bash | zsh | fish | pwsh | oh-my-posh | 有效 |
| zsh | Powerlevel10k | 有效* |
| zsh | Spaceship | 有效* |
| zsh | oh-my-zsh | 有效 |
| zsh | prezto | 有效* |
| ssh | 有效 | |
| bash | oh-my-bash | 不支持 |
| bash | bash-it | 不支持 |
| bash | SBP | 不支持 |
| bash | synth-shell-prompt | 不支持 |
| bash | zsh | Powerline-shell | 不支持 |
| zsh | zplug | 不支持 |
| fish | tide | 不支持 |
| fish | oh-my-fish | 不支持 |
已知不兼容情况
题为“已知不兼容情况”的章节如果您在使用提示符时遇到问题,请查看下文或我们的 已知问题 以获取更多故障排除步骤。
Starship
题为“Starship”的章节Starship 设置
题为“Starship 设置”的章节已知某些 ~/.config/starship.toml 设置会导致 Warp 出错。使用 # 或 DEL 处理以下行以解决已知错误
# Get editor completions based on the config schema'' = 'https://starship.rs/config-schema.json'
# Disables the custom module[custom]disabled = false对于 fish Shell(bash|zsh 可选),通过在您的 ~/.config/starship.toml 中放入以下内容来禁用 Starship 中的多行提示符
[line_break]disabled = true您可能还会看到与超时相关的错误。您可以在 ~/.config/starship.toml 中设置 command_timeout 变量来修复此问题。更多信息请参见 starship 文档。
Starship + bash
题为“Starship + bash”的章节如果您的 默认 Shell 是 /bin/bash,Starship 提示符可能无法正确渲染。要 绕过 该问题,我们建议您升级 bash,通过 echo $(which bash) 找到路径,然后将该路径放入 Settings(设置)> Features(功能)> Session(会话)> “Startup shell for new sessions”(新会话启动 Shell)。
Starship + zsh
题为“Starship + zsh”的章节如果您想在 zsh 上恢复 Starship 提示符后的附加行,请将以下内容添加到您的 ~/.zshrc 文件末尾: PROMPT="${PROMPT}"$'\n'
Powerlevel10k
题为“Powerlevel10k”的章节安装 Powerlevel10k (P10k) 提示符时,我们建议您使用 Meslo Nerd Font。
P10K 可能会将箭头分隔符显示为灰色而不是彩色。这些字符的颜色由于 Warp 的最小对比度设置而被渲染为灰色。要 绕过 此问题,请转到 Settings(设置)> Appearance(外观)> Text(文本)> Enforce minimum contrast(强制最小对比度)并将其设置为“Never”。
Warp 确实支持 p10k 1.19.0 及更高版本。确保您已安装最新版本,并在安装/更新 p10k 后重启 Warp。然后按 上述 说明启用自定义提示符,它应该可以正常工作。
Spaceship
题为“Spaceship”的章节此提示符可能会导致 Warp 输入编辑器中的预输入出现问题。要 绕过 该问题,请运行 echo "SPACESHIP_PROMPT_ASYNC=FALSE" >>! ~/.zshrc。
Prezto
题为“Prezto”的章节尽管 Warp 对 prezto 的提示符有支持,但在 .zpreztorc 中启用 prezto 实用程序模块 是不受支持的,就像许多其他不兼容的自动补全 插件一样。
为 Warp 禁用不支持的提示符
题为“为 Warp 禁用不支持的提示符”的章节我们建议使用 Warp 的默认提示符或安装受支持的工具之一,请参阅 兼容性表。您可以为 Warp 禁用不支持的提示符,如下所示
if [[ $TERM_PROGRAM != "WarpTerminal" ]]; then##### WHAT YOU WANT TO DISABLE FOR WARP - BELOW
# Unsupported Custom Prompt Code
##### WHAT YOU WANT TO DISABLE FOR WARP - ABOVEfiiTerm2
题为“iTerm2”的章节iTerm2 Shell 集成会破坏 Warp,启用此功能后,您的自定义提示符将无法显示。如果您来自 iTerm2,请检查您的 dotfiles。我们建议为 Warp 禁用此集成,如下所示
if [[ $TERM_PROGRAM != "WarpTerminal" ]]; then##### WHAT YOU WANT TO DISABLE FOR WARP - BELOW
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
##### WHAT YOU WANT TO DISABLE FOR WARP - ABOVEfi