我如何获得彩色打击?
我怎样才能让bash看起来像这样?
在文本编辑器中打开~/.bashrc
并取消注释行:
#force_color_prompt=yes
成为:
force_color_prompt=yes
保存然后执行source ~/.bashrc
我提出了这个解决方案:
- 在编辑器中打开〜/ .bashrc
-
复制它并将其添加到.bashrc文件的末尾:
PS1='\[\033[1;36m\]\u\[\033[1;31m\]@\[\033[1;32m\]\h:\[\033[1;35m\]\w\[\033[1;31m\]\$\[\033[0m\] '
-
保存文件并重新启动bashrc:
source ~/.bashrc
有关可用颜色和完整选项的完整列表,请查看以下链接:
- wiki.ubuntuusers
- bash的滤色图表
一个更“通用”的版本 – 应该适用于各种环境:
(取决于terminfo)
将其插入$HOME/.bashrc
:
function fgtab { echo "tput setf/setb - Foreground/Background table" for f in {0..7}; do for b in {0..7}; do echo -en "$(tput setf $f)$(tput setb $b) $f/$b " done echo -e "$(tput sgr 0)" done } # The prompt in a somewhat Terminal -type independent manner: cname="$(tput setf 3)" csgn="$(tput setf 4)" chost="$(tput setf 2)" cw="$(tput setf 6)" crst="$(tput sgr 0)" PS1="\[${cname}\]\u\[${csgn}\]@\[${chost}\]\h:\[${cw}\]\w\[${csgn}\]\$\[${crst}\] "
然后执行source ~/.bashrc
。
之后, fgtab
将显示带有数字的颜色表。 这些数字用于tput setf n
和tput setb n
,其中’n’是数字,’f’代表’foreground’,’b’代表’background’颜色。
tput sgr 0
会将前景色和背景色重置为默认值。
正如您所看到的,更改用于提示的颜色变得非常简单(只需在$HOME/.bashrc
编辑相同的数字)。
如果您希望获得带有背景n的所有提示,请在$cname
添加$(tput setb n)
。
@ daniel451在$ HOME / .bashrc中试试这个
PS1='\[\033[6;31m\]-daniel\[\033[5;51m\]@\[\033[3;33m\]UbuntuUltrabook\[\033[3;35m\]\$\[\033[0;34m\]\a\[\033[0m\] '
你会得到你想象的。