如何在命令后永久更改终端的外壳提示符颜色并创建新的空行?

问题描述 投票:0回答:1

[在尝试进行更改之前,我有PS1="\n$PS1"。我的别名PS1="\e[0;34m[\u@ \W]\$ \e[m"中目前有.bash_profile,但它没有给我我想要的行为。当我编写命令并在完成之前到达该行的末尾时,终端不会继续前进到下一行。相反,它返回到我正在处理的行的开头,并在我继续键入时以视觉方式覆盖bash提示和之后的所有内容。当终端到达上一行的末尾时,如何使终端移动到新行,以及如何在每个命令之前/之后都将其留空?

[我试图将bash提示符颜色永久更改为蓝色,并在运行命令以使终端更易于阅读之后创建新的空行。

谢谢

[刚意识到我正在查看有关在Linux上应该用于Mac的shell提示更改颜色的指南。

bash terminal
1个回答
0
投票

[请看this这是我的各种带有颜色和git支持的命令提示符

enter image description here

#!/bin/bash

case $1 in '--remove' | '-r') sed '/[oOº]_[oOº]/d' -i ~/.bashrc; exit 0;; esac

cat >> ~/.bashrc << 'EOF'
#---------------------------------------------{ Info bar }----------------------------------------------+ o_o
line_simbol='-'                                                                                       # | O_O
faces=(O_o o_O o_o O_O º_o º_O O_º o_º º_º); facesN=${#faces[@]} # Face types                         # | o_º
declare -A paint=( # Colors     |   Effects                                                           # | O_O
                [green]='\e[32m' [norm]='\e[0m'                                                       # | O_o
                [yelow]='\e[33m' [bold]='\e[1m'                                                       # | O_o
                 [blue]='\e[94m'  [dim]='\e[2m')                                                      # | o_o
#-------------------------------------------------------------------------------------------------------+ º_O
face() { printf "${paint[yelow]}${faces[$((RANDOM % $facesN))]}${paint[norm]}"; } # Random face       # | º_º
info() {                                                                                              # | o_º
    [[ -d .git ]] && {  # If in git project folder add git status to info bar output                  # | O_o
        git_clr=('GIT' $(git -c color.ui=always status -sb)) # Colored output 4 info                  # | o_O
        git_tst=('GIT' $(git                    status -sb)) # Simple  output 4 test                  # | o_o
    }                                                                                                 # | o_o
                                                                                                      # | o_O
    nametest="{ $HOSTNAME }"                                                                          # | O_o
    sign="{ ${paint[norm]}$HOSTNAME${paint[green]} }"                                                 # | o_o
    printf -v line  "%${COLUMNS}s"; line=${line// /$line_simbol}                                      # | O_o
    printf -v line2 "%$[($COLUMNS-${#nametest})/2]s"; line2=${line2// /$line_simbol}                  # | O_O
    signtest="$line2{ $HOSTNAME }$line2"; [[ ${#signtest} -lt $COLUMNS ]] && sign+=$line_simbol       # | o_o
                                                                                                      # | o_o
    D=$(printf "%(%a %d %b %T)T")                             # Date & time                           # | O_o
    T=" O_o $PWD  ${git_tst[*]} $D o_O "                      # Test string                           # | o_o
    S=$[$COLUMNS-${#T}]; [[ $S -lt 0 ]] && S=0                # Count spaces                          # | o_º
    date="${paint[dim]}$D${paint[norm]}"                      # Date & time                           # | O_o
    line="${paint[green]}$line${paint[norm]}\n"               # Create line                           # | O_o
    home="${paint[bold]}${paint[blue]}$PWD${paint[norm]}"     # Home dir info                         # | o_o
    sign="${paint[green]}$line2$sign$line2${paint[norm]}\n"   # Hostname sign                         # | O_o
           #------+-----+-------+------+------------+-----+-------+--------+                          # | o_o
           # Line | O_o |homedir|Spaces| Git status | Date|  o_O  |  Line  |                          # | o_O
           #------+-----+-------+------+------------+-----+-------+--------+                          # | O_O
    printf "$sign $(face) $home %${S}s ${git_clr[*]} $date $(face) \n$line" # Final info string       # | O_o
}                                                                                                     # | O_o
#-------------------------------------------------------------------------------------------------------+ o_o
PS1='${debian_chroot:+($debian_chroot)}\n$(info)\n$ '                                                 # | º_O
                                                                                                      # | o_º
case "$TERM" in xterm*|rxvt*)                                                                         # | O_o
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)} ${faces[$[RANDOM % $facesN]]} \w\a\]$PS1";;        # | O_º
esac                                                                                                  # | o_O
#-------------------------------------------------------------------------------------------------------+ O_o
EOF
© www.soinside.com 2019 - 2024. All rights reserved.