Ctrl + A快捷方式在Bash中非常有用

app*_*mac 1 unix macos bash

我刚刚在OS X中完成了自定义我的Bash命令提示符.简而言之,它现在允许我从新行开始输入命令:

alexey::machine { ~/rails/jutge } (git: static-pages) 12:55 PM
-> bundle exec rspec spec/requests/static_pages_spec.rb
Run Code Online (Sandbox Code Playgroud)

当我决定使用Ctrl + A快捷键移动到行的开头时,我转到第4个字符,并且它之前的所有三个字符都被删除(我用'$'符号标记了光标位置):

-> bun$dle exec rspec spec/requests/static_pages_spec.rb
Run Code Online (Sandbox Code Playgroud)

我的意思是,前三个字符仍然显示,但不可访问且不可编辑.

我将不胜感激任何有关如何解决它的说明.谢谢.

我的.bash_profile和.bashrc内容:

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

PS1="\e[1;33m\u::\h\e[m \e[0;32m{ \w }\e[m\e[0;36m\$(parse_git_branch)\e[m\e[1;34m\@\e[m\e[1;35m\n->\e[m "
Run Code Online (Sandbox Code Playgroud)

che*_*ner 5

您需要在\ [... \]中包含PS1的非打印字符,以便bash可以正确计算提示的大小.

PS1="\[\e[1;33m\]\u::\h\[\e[m\] \[\e[0;32m\]{ \w }\[\e[m\e[0;36m\]\$(parse_git_branch)\[\e[m\e[1;34m\]\@\[\e[m\e[1;35m\]\n->\[\e[m\] "
Run Code Online (Sandbox Code Playgroud)