プロンプトのシンボルが破損する原因は何ですか?どこかに逃げる機会を逃したようです。

プロンプトのシンボルが破損する原因は何ですか?どこかに逃げる機会を逃したようです。

端末プロンプトとvimインスタンスの最下部に「壊れた」記号が表示されます。これは一種のカラーコード参照のようですが、どこから来たのかわかりません。

parse_git_branch()オンラインで機能を見つけましたstrip_colors()。 PS1設定自体は、次のいずれかで作成されます。

https://scriptim.github.io/bash-prompt-generator/

http://ezprompt.net/

私はbashで「あまり良くない」ことを明確にするためにこれを言うことです:p

回避策に関するアドバイスはありますか?よろしくお願いします!

早く

プロンプトに「破損」記号が表示されます。

精力

また、vimディスプレイの最下部にもあります。

force_color_prompt=yes

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

strip_colors() {
    sed 's/\\[eE][[0-9]*;[0-9]*m//g' <<< $PS1
    # You can use it like this
    #     PS1="..."
    #     export PS1=$(strip_colors)
}

if [ "$color_prompt" = yes ]; then
    ...
    # green with 'default' text colors
    PS1="\n\[\e[32m\](\[\e[0m\]\u\[\e[32m\])(\[\e[0m\]jobs:\j\[\e[32m\])(\[\e[0m\]\w\[\e[32m\])\$(parse_git_branch)\[\033[00m\]\n\[\e[0m\]\$ "

else
    PS1="\n\[\e[32m\](\[\e[0m\]\u\[\e[32m\])(\[\e[0m\]jobs:\j\[\e[32m\])(\[\e[0m\]\w\[\e[32m\])\$(parse_git_branch)\[\033[00m\]\n\[\e[0m\]\$ "
    export PS1=$(strip_colors)
fi
unset color_prompt force_color_prompt

ベストアンサー1

@Quasimodoと@JdeBPに感謝!

その機能を削除し、strip_colors()parse_git_branch()の機能に置き換えました。それ以来、何の問題もありませんでした。

# get current branch in git repo, from ezprompt.net
function parse_git_branch() {
    BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
    if [ ! "${BRANCH}" == "" ]
    then
        STAT=`parse_git_dirty`
        echo "[${BRANCH}${STAT}]"
    else
        echo ""
    fi
}

# get current status of git repo
function parse_git_dirty {
    status=`git status 2>&1 | tee`
    dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
    untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
    ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
    newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
    renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
    deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
    bits=''
    if [ "${renamed}" == "0" ]; then
        bits=">${bits}"
    fi
    if [ "${ahead}" == "0" ]; then
        bits="*${bits}"
    fi
    if [ "${newfile}" == "0" ]; then
        bits="+${bits}"
    fi
    if [ "${untracked}" == "0" ]; then
        bits="?${bits}"
    fi
    if [ "${deleted}" == "0" ]; then
        bits="x${bits}"
    fi
    if [ "${dirty}" == "0" ]; then
        bits="!${bits}"
    fi
    if [ ! "${bits}" == "" ]; then
        echo " ${bits}"
    else
        echo ""
    fi
}

# Use like:
# export PS1="\`parse_git_branch\` "

おすすめ記事