如何防止终端线覆盖自身?

the*_*aer 16 command-line

在小于全屏的终端窗口中,如果我输入一个长命令,它会开始覆盖我所在的当前行。如果我输入一个额外的行,它最终会移动到下一行。有谁知道如何解决这一问题?

这是视觉上发生的事情:

终端截图

编辑:这些是我的提示设置:

PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\033[1m`__git_ps1`\033[0m\$ '
TERM=xterm
Run Code Online (Sandbox Code Playgroud)

.bashrc

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\033[1m`__git_ps1`\033[0m\$ '
fi

# 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
Run Code Online (Sandbox Code Playgroud)

Jul*_*ght 11

由于某种原因,终端大小错误报告。当您调整终端大小时,它应该会发生变化。

在你的 .bashrc 命令文件中试试这个:

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
Run Code Online (Sandbox Code Playgroud)

  • 行数为 24,列数为 80。调整窗口大小确实会更改这些值,但文本仍然混乱。 (3认同)

Jer*_*naw 8

我在这里找到了答案。得票最多的答案为我解决了这个问题。

总而言之,我必须将我的格式包装在 \[ \]
export PS1='\[\033[1;32m\]$(whoami)@$(hostname): \[\033[0;37m\]$(pwd)$ \[\033[0m\]'