【发布时间】:2017-07-01 17:34:06
【问题描述】:
【问题讨论】:
-
有几十个包有花哨的提示设置。选择你喜欢的;确保它适用于您喜欢的 shell。 Arpit 下面提到了 zsh,需要从 bash 切换到 zsh。
【问题讨论】:
【讨论】:
(master)$[00 m。
如果您想保留现有 linux 终端的相同颜色并显示当前的 git 分支,您可以将以下内容添加到您的默认 PS1。
PS1 基本上告诉您的 bash 提示符要显示什么。 参考:How to Change / Set up bash custom prompt (PS1) in Linux
我使用的是 Ubuntu 20.04,默认 PS1 位于 ~/.bashrc 文件中的 if [ "$color_prompt" = yes ]; then 下。
步骤:
if [ "$color_prompt" = yes ]; then
#show git branch
show_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \[\033[31m\]\$(show_git_branch)\[\033[00m\]$ "
else
PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w \$(show_git_branch)\$ "
fi
整个事情应该是这样的:
#show git branch
show_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \[\033[31m\]\$(show_git_branch)\[\033[00m\]$ "
else
PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w \$(show_git_branch)\$ "
fi
它应该看起来像这样: Terminal with git branch
【讨论】: