简体   繁体   English

“gnome-terminal”的标题在 Ubuntu 中被 .bashrc 覆盖

[英]Title of "gnome-terminal" is being overridden by .bashrc in Ubuntu

I need to open around 20 terminals on the same time and execute different command on each one ,and I'd like also to name each window with a different name.我需要同时打开大约 20 个终端并在每个终端上执行不同的命令,并且我还想用不同的名称命名每个窗口。

I'm using something as follows:我正在使用如下内容:

gnome-terminal --title="some title goes here" -- bash -ic "ls; exec bash"

The new window is opened , shows the title some title goes here and after 1~2 seconds it's being overridden and turns into the path that I'm running the command新窗口打开,显示标题some title goes here ,1~2 秒后它被覆盖并变成我正在运行命令的路径

 gnome-terminal --title="some title goes here" -- bash -ic "ls; exec bash"

from.从。

Here is my .bashrc :这是我的.bashrc

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#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

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

[ -f ~/.fzf.bash ] && source ~/.fzf.bash

# function
parse_git_branch() {
  if [ -n "$(git rev-parse --git-dir 2> /dev/null)" ]; then
    echo "($(git rev-parse --abbrev-ref HEAD)) "
  fi
}

# environment customization
# PS1="[\t \D{%F} \u@\h \W\a]$ "
PS1="$PS1-[\t \D{%F}]$ "
export PS1="$PS1\$(parse_git_branch)"


# HSTR configuration - add this to ~/.bashrc
alias hh=hstr                    # hh to be alias for hstr
export HSTR_CONFIG=hicolor       # get more colors
shopt -s histappend              # append new history items to .bash_history
export HISTCONTROL=ignorespace   # leading space hides commands from history
export HISTFILESIZE=10000        # increase history file size (default is 500)
export HISTSIZE=${HISTFILESIZE}  # increase history size (default is 500)
# ensure synchronization between bash memory and history file
export PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}"
# if this is interactive shell, then bind hstr to Ctrl-r (for Vi mode check doc)
if [[ $- =~ .*i.* ]]; then bind '"\C-r": "\C-a hstr -- \C-j"'; fi
# if this is interactive shell, then bind 'kill last command' to Ctrl-x k
if [[ $- =~ .*i.* ]]; then bind '"\C-xk": "\C-a hstr -k \C-j"'; fi


function changeTitle(){
  if [[ -z "$ORIG" ]]; then
    ORIG="$PS1"
  fi
  TITLE="\[\e]2;$*\a\]"
  PS1="${ORIG}${TITLE}"
}

### ALIASES ###
alias k='kubectl'

Any idea how to fix this ?知道如何解决这个问题吗?

The prompt set in PS1 contains screen control codes which overwrite the window title. PS1中设置的提示包含覆盖窗口标题的屏幕控制代码。

If you don't want the prompt to change your window title, take out the snippet which does that.如果您不希望提示更改窗口标题,请取出执行此操作的代码段。

Here's a slight edit to let you set no_title_change in the calling shell.这是一个轻微的编辑,可让您在调用 shell 中设置no_title_change This would replace the similar snippet in your current .bashrc ;这将替换您当前.bashrc中的类似片段; the real change it that we change the variable $TERM to a slightly more complex (and slightly hacky) parameter expansion .真正的改变是我们将变量$TERM更改为稍微复杂(并且有点 hacky)的参数扩展

...

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

...

If you unconditionally want to remove the title-changing logic, just replace this snippet with nothing.如果您无条件地想要删除标题更改逻辑,只需将此代码段替换为空即可。

The use case of opening a separate terminal window for each in a set of tasks is dubious;为一组任务中的每个任务打开一个单独的终端窗口的用例是可疑的; a better practice generally is to run your tasks as background processes, each with output to a file.更好的做法通常是将任务作为后台进程运行,每个进程都有输出到文件。 Then you can automate monitoring and logging for the entire scenario, and avoid silly problems like terminating a process by mistake by accidentally closing the wrong terminal window;然后您可以对整个场景进行自动化监控和日志记录,避免因不小心关闭错误的终端窗口而误终止进程等愚蠢问题; and managing the processes remotely from multiple locations becomes feasible.从多个位置远程管理流程变得可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM