如何从 Sugar on a Stick 的终端提示中删除返回码?

如何从 Sugar on a Stick 的终端提示中删除返回码?

我在用棒上的糖(Fedora 23) 0.106 for i686 作为发行版。

当我使用终端时,我得到了一个非常奇怪的行为。

奇怪的代码

例如,当我输入时ls,我得到环境变量的值]777;notify;Command completed;ls[sugar] # 在哪里。[sugar] #PS1

我的.bashrc样子是这样的:

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

# Prompt
PS1="[sugar] # "

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

当我注释掉该Source global definitions部分时,问题就消失了。然而,当我想修改时,/etc/bashrc我读到修改这个文件是不明智的。这是文件:

# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

# are we an interactive shell?
if [ "$PS1" ]; then
  if [ -z "$PROMPT_COMMAND" ]; then
    case $TERM in
    xterm*|vte*)
      if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
      elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
          PROMPT_COMMAND="__vte_prompt_command"
      else
          PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
      fi
      ;;
    screen*)
      if [ -e /etc/sysconfig/bash-prompt-screen ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
      else
          PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
      fi
      ;;
    *)
      [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
      ;;
    esac
  fi
  # Turn on parallel history
  shopt -s histappend
  history -a
  # Turn on checkwinsize
  shopt -s checkwinsize
  [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
  # You might want to have e.g. tty in prompt (e.g. more virtual machines)
  # and console windows
  # If you want to do so, just add e.g.
  # if [ "$PS1" ]; then
  #   PS1="[\u@\h:\l \W]\\$ "
  # fi
  # to your custom modification shell script in /etc/profile.d/ directory
fi

if ! shopt -q login_shell ; then # We're not a login shell
    # Need to redefine pathmunge, it get's undefined at the end of /etc/profile
    pathmunge () {
        case ":${PATH}:" in
            *:"$1":*)
                ;;
            *)
                if [ "$2" = "after" ] ; then
                    PATH=$PATH:$1
                else
                    PATH=$1:$PATH
                fi
        esac
    }

    # By default, we want umask to get set. This sets it for non-login shell.
    # Current threshold for system reserved uid/gids is 200
    # You could check uidgid reservation validity in
    # /usr/share/doc/setup-*/uidgid file
    if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
       umask 002
    else
       umask 022
    fi

    SHELL=/bin/bash
    # Only display echos from profile.d scripts if we are no login shell
    # and interactive - otherwise just process them to set envvars
    for i in /etc/profile.d/*.sh; do
        if [ -r "$i" ]; then
            if [ "$PS1" ]; then
                . "$i"
            else
                . "$i" >/dev/null
            fi
        fi
    done

    unset i
    unset -f pathmunge
fi
# vim:ts=4:sw=4

我能做什么呢?

答案1

除了PS1环境变量之外,PROMPT_COMMAND环境变量还会影响您的提示符。从 bash 手册页:

如果设置,该值将在发出每个主提示之前作为命令执行

正是该命令将不需要的内容添加到提示中。您可以通过取消设置 .bashrc 中的变量来停止该行为:

unset PROMPT_COMMAND

答案2

注释字符串,如图所示

sudo vim /etc/profile.d/vte.sh
...
_vte_prompt_command() {
...
#printf "\033]777;notify;命令完成;%s\007\033]0;%s@%s:%s\007%s" "${command}" "${USER}" "${主机名%%.*}" "${pwd}" "$(__vte_osc7)"
}

答案3

当从用户终端运行 su 时,Fed 28 上也会发生这种情况。运行“su - ”不会产生这个问题。

/etc/bashrc 和 /etc/profile.d/vte.sh 中有一个相同的代码片段用于测试环境。并设置 PROMPT_COMMAND。通过查看代码可以发现正在执行的是前者。

答案4

在 EL7 中,我们发现更新 mate-terminal 和 vte* 软件包有效。

您将需要关闭所有 mate 终端并重新打开它们,因为 mate 保持相同的进程并启动新窗口,因此需要重新启动才能启动新库。

相关内容