現在の行を上書きする Bash プロンプト

現在の行を上書きする Bash プロンプト

ここでこのスレッドと同様の問題がありました。コマンドラインがその行を覆っていて、上矢印がすべてのテキストを覆っていました。

端末プロンプトが正しくラップされません。

私が走るとき

$ shopt  | grep checkwinsize
checkwinsize    on

私のbashrcのps1部分のうち、正しい部分をラップしなかったため、問題が発生したようです。 []内のスクリプト。他のスレッドの説明に従ってみましたが、役に立たないようです。

これは私のbashrcの一部です。スクリプト。

force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    # We have color support; assume it's compliant with Ecma-48
    # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
    # a case would tend to support setf rather than setaf.)
    color_prompt=yes
    else
    color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

私のbashrcに問題がありますか?この問題を引き起こすスクリプトは何ですか?

私は4.13.0-36汎用カーネルでUbuntu 16.04.4 Cinnamonバージョン3.6.7を実行しています。

ありがとうございます。

ベストアンサー1

何か欠けているかもしれませんが、これを再現できないか、スクリプトに何の問題も見られません。

まず、問題が実際にbashrcのこの部分にあることを確認したいと思います。 "echo $PS1"を実行して、プロンプトが他の場所で修正されていることを確認してください。確実にするために、以下を実行して問題が引き続き発生するかどうかを確認してください。

bash -noprofile -norc
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

問題が解決しない場合、原因は端末エミュレータである可能性があります。使用している端末エミュレータの "$TERM"値が正しいことを確認したら、別のエミュレータを試してください。端末を再初期化し、PS1を手動で設定することもできます。 xtermを使用するとします。

TERM=xterm
tset $TERM
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

おすすめ記事