因此,我已经非常擅长这里的任务,从编辑所有帖子到回答问题,所以我认为是时候问一个问题了:
技术信息
发行版:Gentoo
桌面环境:KDE
终端仿真器:Kterm
问题
任何长期使用 Gentoo 的人都会习惯终端和源代码的流动。因此,即使在 KDE 中,我也开始依赖终端,使用如下命令:
kdesudo kate /etc/portage/make.conf
sudo emerge -uDav world
这些命令按预期工作,我的问题是 kterm 的标题显示username:sudo
我希望它显示用户名:sudo 提升的命令,或者用户名:elavated 命令。
我使用以下配置文件:
# /etc/profile: login shell setup
#
# That this file is used by any Bourne-shell derivative to setup the
# environment for login shells.
#
# Load environment settings from profile.env, which is created by
# env-update from the files in /etc/env.d
if [ -e /etc/profile.env ] ; then
. /etc/profile.env
fi
# You should override these in your ~/.bashrc (or equivalent) for per-user
# settings. For system defaults, you can add a new file in /etc/profile.d/.
export EDITOR=${EDITOR:-/bin/nano}
export PAGER=${PAGER:-/usr/bin/less}
# 077 would be more secure, but 022 is generally quite realistic
umask 022
# Set up PATH depending on whether we're root or a normal user.
# There's no real reason to exclude sbin paths from the normal user,
# but it can make tab-completion easier when they aren't in the
# user's PATH to pollute the executable namespace.
#
# It is intentional in the following line to use || instead of -o.
# This way the evaluation can be short-circuited and calling whoami is
# avoided.
if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${ROOTPATH}"
else
PATH="/usr/local/bin:/usr/bin:/bin:${PATH}"
fi
export PATH
unset ROOTPATH
if [ -n "${BASH_VERSION}" ] ; then
# Newer bash ebuilds include /etc/bash/bashrc which will setup PS1
# including color. We leave out color here because not all
# terminals support it.
if [ -f /etc/bash/bashrc ] ; then
# Bash login shells run only /etc/profile
# Bash non-login shells run only /etc/bash/bashrc
# Since we want to run /etc/bash/bashrc regardless, we source it
# from here. It is unfortunate that there is no way to do
# this *after* the user's .bash_profile runs (without putting
# it in the user's dot-files), but it shouldn't make any
# difference.
. /etc/bash/bashrc
else
PS1='\u@\h \w \$ '
fi
else
# Setup a bland default prompt. Since this prompt should be useable
# on color and non-color terminals, as well as shells that don't
# understand sequences such as \h, don't put anything special in it.
PS1="${USER:-$(whoami 2>/dev/null)}@$(uname -n 2>/dev/null) \$ "
fi
for sh in /etc/profile.d/*.sh ; do
[ -r "$sh" ] && . "$sh"
done
unset sh
etc/bashrc/bashrc
当我回家时我会将我的文件插入这里......
我留下评论是为了给这里的新用户一个答案。因此,即使您是新来的,最彻底、有效的答案也将获得积分。我想要一个带有参考文献和链接的格式正确的答案
更新
答案1
不确定kterm
,但可能它是xterm
转义兼容的 - 大多数都是。如果是这样,那么您需要在提示中添加一些内容设置窗口标题:
3.1 xterm 转义序列
通过使用 XTerm 转义序列,可以在运行的 xterm 中更改窗口和图标标题。以下序列在这方面很有用:
ESC]0;stringBEL
-- 将图标名称和窗口标题设置为字符串ESC]1;stringBEL
-- 将图标名称设置为字符串ESC]2;stringBEL
-- 设置窗口标题为字符串
...其中
ESC
是转义字符 (\033
),BEL
是响铃字符 (\007
)。
您可以将它们放在非打印转义之间的提示中 - 如果您使用的是bash
.在该 shell 中您可以使用:
PS1="\[$(printf '\033]0;"${USER}@${BASH_COMMAND}"\007')\]"
或者您可以将类似的内容放入$PROMPT_COMMAND
环境变量中。
但...
显然 konsole
关于是否允许通过转义序列设置窗口名称,版本有所不同。在版本 3 周期的某个时刻,它停止解释序列并仅在更改选项卡标题时ESC]33;Window nameBEL
尊重序列。xterm
自从4.9版本不过,konsole
至少应该遵循奇怪的ESC]30;Tab NameBEL
顺序,如果您在设置对话框中将其配置为空,则窗口名称将自动从当前活动选项卡克隆。
我不清楚您是否可以使用更常见的xterm
转义来设置窗口标题。但是,如果此处提供的信息不足以获得令人满意的解决方案,那么我怀疑您会通过单击附加到 4.9 版中记录的相关更改的链接找到一些有用的信息。变更日志在这里。