0

I am getting some "corrupted" symbols diplaying both in my terminal prompt and also in the lowest portion of my vim instance. These seem to be some sort of color code reference, but I can't pinpoint where they might be coming from.

I found the parse_git_branch() and strip_colors() functions online. And the PS1 settings themselves were generated from either

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

http://ezprompt.net/

I say that just to clarify that I'm "not that good" at bash :p

Any tips on how to resolve? Thank you in advance!

prompt

"Corrupted" symbols appearing in prompt

vim

And also in the lowest portion of the vim display

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
3
  • I would be very doubtful of any function that claims to uncolor my PS1 prompt, as well as some other function that may insert anything in it, since PS1 contains all kinds of weird escape sequences and is thus likely to break if you blindly insert things there.
    – Quasímodo
    Sep 26, 2020 at 11:44
  • If I use the PS1 line and remove the parse_git_branch thing, the prompt displays correctly. If you can reproduce that, consider changing or altogether ditching those functions.
    – Quasímodo
    Sep 26, 2020 at 11:46
  • You're leading people on a wild goose chase. edit your question to tell people the value of your TERM environment variable and the name of the terminal emulator that you are using.
    – JdeBP
    Sep 26, 2020 at 12:38

1 Answer 1

0

Thank you @Quasimodo and @JdeBP!

I got rid of the strip_colors() function and replaced the parse_git_branch() function with the following. Since then I haven't had any more issues.

# 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\` "

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .