这些天我遇到了一个奇怪的Bash问题。在终端中,当我按下命令ctrl+u
并想要清除当前输入行而不是清除它时,有时会通过离开来截断当前输入行某些字母从头开始。
例如,在下面的示例中,我首先按4次ctrl+p
来查找最近键入的命令。然后当我停在ls /Users/Heros/dev/gitinspector/gitinspector-0.3.2
命令时。现在我按ctrl+u
。当前输入行未完成清除,如图所示。它会留下ls /Users
。
我一直在谷歌搜索这个问题好几天但没有运气。以前有人遇到过类似的问题吗?提前感谢您提供的任何线索。
顺便说一句,我正在使用Bash,而我使用的终端是iTerms2。我尝试了标准的终端应用程序,问题仍然存在。
为了帮助调查,我粘贴了我正在使用的~/.bash_profile
,以防它有用。
# Add Homebrew `/usr/local/bin` and User `~/bin` to the `$PATH`
PATH=/usr/local/bin:$PATH
PATH=$HOME/bin:$PATH
export PATH
GRADLE_HOME='~/dev/gradle-2.4'
export GRADLE_HOME
PATH=$PATH:$GRADLE_HOME/bin
export PATH
# Load the shell dotfiles, and then some:
# * ~/.path can be used to extend `$PATH`.
# * ~/.extra can be used for other settings you don’t want to commit.
for file in ~/.{path,bash_prompt,exports,aliases,functions,extra}; do
[ -r "$file" ] && source "$file"
done
unset file
alias gitinspector='~/dev/gitinspector/gitinspector-0.3.2/gitinspector/gitinspector.py'
#export java env
export JAVA_6_HOME='/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home'
export JAVA_7_HOME='/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home'
export JAVA_8_HOME='/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home'
#add JAVA_OPTS
JAVA_OPTS="-Xms256m -Xmx1024m -XX:MaxNewSize=512m"
export JAVA_OPTS
#switch among jdk6/7/8
alias jdk6='export JAVA_HOME=$JAVA_6_HOME'
alias jdk7='export JAVA_HOME=$JAVA_7_HOME'
alias jdk8='export JAVA_HOME=$JAVA_8_HOME'
export JAVA_HOME=$JAVA_8_HOME
alias jshint='~/.npm/jslint/0.9.0/package/node_modules/jshint/bin/jshint' #add jshint env
alias chrome='/usr/bin/open -a "/Applications/Google Chrome.app"' # open an url or html from command
alias xee='/usr/bin/open -a "/Applications/Xee.app"'
alias thunder='/usr/bin/open -a "/Applications/Thunder.app"'
alias macdown='/usr/bin/open -a "/Applications/MacDown.app"'
alias notes='/usr/bin/open -a "/Applications/Notes.app"'
alias pdf='/usr/bin/open -a "/Applications/Preview.app"'
alias gif='/usr/bin/open -a "/Applications/LICEcap.app"'
#add maven env
MAVEN_HOME=$HOME/dev/apache-maven-3.3.3
M2_HOME=$HOME/dev/apache-maven-3.3.3
PATH=$MAVEN_HOME/bin:$PATH
export MAVEN_HOME
export M2_HOME
export PATH
alias fq="~/dev/code_sh/auto_gfw.sh"
alias grep='grep --color=auto'
alias listen="lsof -P -i -n"
mcd() { mkdir -p "$1";cd "$1";} #enter into dir once a dir created
cls() { cd "$1"; ls; } #list after enter into a dir
extract() {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()";;
esac
else
echo "'$1' is not a valid file"
fi
}
#add path for mysql
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
PATH=$PATH:/usr/local/mysql/bin
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
#rvm
export PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
#set bash to use vi mode as default rather than emacs
#set -o vi
function rvm_version {
local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}')
[ "$gemset" != "" ] && gemset="@$gemset"
local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}')
[ "$version" != "" ] && version="$version"
local full="ruby$version$gemset"
[ "$full" != "" ] && echo "$full "
}
#function parse_ruby_version {
#ruby -v | cut -d" " -f2
#}
function color_my_prompt {
#local __user_and_host="\e[m"Shibin"@\h $ "
local __user_and_host="\e[\033[36m\]"Shibin"@\h $ "
local __cur_location="\[\033[01;34m\]\w"
local __git_branch_color="\[\033[31m\]"
#local __git_branch="\`ruby -e \"print (%x{git branch 2> /dev/null}.grep(/^\*/).first || '').gsub(/^\* (.+)$/, '(\1) ')\"\`"
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`'
local __prompt_tail="\[\033[35m\]$"
local __last_color="\[\033[00m\]"
# local __rvm_color="\[\033[01m\]"
#export PS1="$__user_and_host $__cur_location $__rvm_color$(\rvm_version) $__git_branch_color$__git_branch$__prompt_tail$__last_color "
export PS1="$__user_and_host $__cur_location $__git_branch_color$__git_branch$__prompt_tail$__last_color "
}
color_my_prompt
#THIS MUST BE AT THE END OF THE FILE FOR GVM TO WORK!!!
[[ -s "/Users/Heros/.gvm/bin/gvm-init.sh" ]] && source "/Users/Heros/.gvm/bin/gvm-init.sh"

答案 0 :(得分:0)
最后,我得到一个解决方法,只需禁用strcpy(x+1, SEQX);
功能,问题就消失了。我之前从网上复制了这个功能,目前我不知道它有什么问题。
任何找到根本原因的人,我都会接受你的回答,谢谢。