LOGAN
LOGAN

Reputation: 502

Terminal line has broken itself when type long characters on OSX

I use Terminal very Often which mean is i have situation that i have to put long phrase for executing command from Terminal to App. I have no idea when this line sucking( or breaking) had been happening now. is there any solution to fix this without sizing of terminal?

enter image description here

enter image description here

Upvotes: 1

Views: 1384

Answers (1)

Yoric
Yoric

Reputation: 1784

Based on our discussion, you should edit your ~/.bash_profile and replace the following line:

export PS1="\u@\h \W[\033[32m]\$(parse_git_branch)[\033[00m] $ "

with this line:

export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "

Then open a new terminal window, and try if it's any better.

When customizing the PS1 variable, you need to surround non-printable character with \[ and \] or else bash doesn't calculate the length of the prompt correctly, hence the overlapping text with the cursor.


UPDATE

I would just replace this block of code:

parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/ (\1)/'
}
export PS1="\u@\h \W[\033[32m]\$(parse_git_branch)[\033[00m] $ "

with this line:

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\] \[\033[33;1m\]\w\[\033[m\] (\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)) \$ "

Or, if you want to stick with your solution, replace it with this correction:

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

export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "

UPDATE2

Replace this line:

export PROMPT_COMMAND="echo -n \(\$(date +%H:%M:%S)\)\ "

With this line:

export PROMPT_COMMAND=update_terminal_cwd

Now your terminal should be OK again! If you want to add the date and time in front of your prompt, Then edit this line:

export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "

like this:

export PS1="($(date +%H:%M:%S)) \u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "

Upvotes: 2

Related Questions