过去可以右键单击选项卡并更改标题。不知道如何做到这一点了。刚刚升级到 Fedora 21。
编辑:我已从 gnome-terminal 切换到 ROXterm
Wes*_*ger 135
在 中创建一个函数~/.bashrc:
function set-title() {
if [[ -z "$ORIG" ]]; then
ORIG=$PS1
fi
TITLE="\[\e]2;$*\a\]"
PS1=${ORIG}${TITLE}
}
Run Code Online (Sandbox Code Playgroud)
然后使用您的新命令设置终端标题。它也适用于名称中的空格
set-title my new tab title
Run Code Online (Sandbox Code Playgroud)
可以随后set-title再次使用(原始 PS1 保留为ORIG)。
don*_*sti 47
的user title代码除去1从gnome-terminal 3.14。要设置标题,您可以使用转义序列:
printf "\e]2;YOUR TITLE GOES HERE\a"
Run Code Online (Sandbox Code Playgroud)
或例如bash:
PROMPT_COMMAND='echo -ne "\033]0;YOUR TITLE GOES HERE\007"'
Run Code Online (Sandbox Code Playgroud)
1:请参阅 gnome错误 724110和 gnome错误 740188。
gee*_*ekQ 26
新版本的 gnome-terminal 丢弃了最有用的专业功能。:-(
我尝试设置并运行旧版本的 gnome-terminal 并比较了替代方案。
如果terminator对您来说太异国情调,这mate-terminal是一个不错的选择!它是 gnome-terminal 的一个分支,并保留了所有好的特性:
您可以从命令行打开多个选项卡给它们不同的标题
mate-terminal --tab -t "aaa" --tab -t "bbb" --tab -t "ccc"
Run Code Online (Sandbox Code Playgroud)你可以设置一个快捷键(我使用Ctrl +按住Shift我)给定在我TLE
Gab*_*les 13
截至 2021 年 3 月,我的新脚本:
我现在有了“设置标题”功能的新版本。对于它的最新版本,请在此处某处搜索我的~/.bash_aliases文件。这就是它可能的样子。它现在有一个-h帮助菜单,而不是PS1第一次运行它时依赖变量的备份,这很挑剔,它只是使用sed's'tream 'ed'itor 命令和正则表达式来去除现有的标题PS1取而代之的是变量中的字符串。
gs_set_title() {
CMD="gs_set_title"
# Help menu
if [ "$1" == "-h" ] || [ "$1" == "-?" ]; then
echo "Set the title of your currently-opened terminal tab."
echo "Usage: $CMD any title you want"
echo " OR: $CMD \"any title you want\""
echo " OR (to make a dynamic title which relies on variables or functions):"
echo " $CMD '\$(some_cmd)'"
echo " OR $CMD '\${SOME_VARIABLE}'"
echo "Examples:"
echo " 1. static title"
echo " $CMD my new title"
echo " 2. dynamic title"
echo " $CMD 'Current Directory is \"\$PWD\"'"
echo " OR $CMD 'Date and time of last cmd is \"\$(date)\"'"
return $EXIT_SUCCESS
fi
TITLE="$@"
# Set the PS1 title escape sequence; see "Customizing the terminal window title" here:
# https://wiki.archlinux.org/index.php/Bash/Prompt_customization#Customizing_the_terminal_window_title
ESCAPED_TITLE="\[\e]2;${TITLE}\a\]"
# Delete any existing title strings, if any, in the current PS1 variable. See my Q here:
# https://askubuntu.com/questions/1310665/how-to-replace-terminal-title-using-sed-in-ps1-prompt-string
PS1_NO_TITLE="$(echo "$PS1" | sed 's|\\\[\\e\]2;.*\\a\\\]||g')"
PS1="${PS1_NO_TITLE}${ESCAPED_TITLE}"
}
Run Code Online (Sandbox Code Playgroud)
原答案:
@Weston Ganger编写了此函数(并在此处发布)以放入~/.bashrc:
function set-title() {
if [[ -z "$ORIG" ]]; then
ORIG=$PS1
fi
TITLE="\[\e]2;$*\a\]"
PS1=${ORIG}${TITLE}
}
Run Code Online (Sandbox Code Playgroud)
然后您可以通过调用设置终端标题set-title TERMINAL NAME(名称周围的引号是可选的)。
对我来说,这看起来很神秘(请参阅我在他的回答下的评论),所以我昨晚花了几个小时阅读和学习,以弄清楚他做了什么以及为什么有效。这是我发现的:
gnome-terminal3.16.2 左右开始(请参阅此答案下的评论),“--title不再支持该选项。” 否则,你就会这样做gnome-terminal --title="my title",就像我以前在这里做的那样。$@而不是$*代表上面脚本中的所有输入参数。显然$@更不容易出错且更兼容,因为它是表示“所有输入参数”的 POSIX 方式。因此,在我下面的版本中,我使用$@代替$*.\[\e]2;new title\a\]PS1PS1="${PS1}\[\e]2;new title\a\]"gnome-terminal--title 争论,这似乎是设置标题的唯一方法。现在,这是我对 Weston Ganger 函数的版本,并附有大量解释性评论。这将进入我的 dotfiles,所以我永远不会丢失它:
# Set the title string at the top of your current terminal window or terminal window tab
set-title() {
# If the length of string stored in variable `PS1_BAK` is zero...
# - See `man test` to know that `-z` means "the length of STRING is zero"
if [[ -z "$PS1_BAK" ]]; then
# Back up your current Bash Prompt String 1 (`PS1`) into a global backup variable `PS1_BAK`
PS1_BAK=$PS1
fi
# Set the title escape sequence string with this format: `\[\e]2;new title\a\]`
# - See: https://wiki.archlinux.org/index.php/Bash/Prompt_customization#Customizing_the_terminal_window_title
TITLE="\[\e]2;$@\a\]"
# Now append the escaped title string to the end of your original `PS1` string (`PS1_BAK`), and set your
# new `PS1` string to this new value
PS1=${PS1_BAK}${TITLE}
}
Run Code Online (Sandbox Code Playgroud)
set-title my tab 1 或者 set-title "my tab 1"set-title $PWD 或者 set-title "$PWD"set-title '$PWD'- 每次您cd进入新目录时,都会更新当前工作目录的标题!set-title '$(date "+%m/%d/%Y - %k:%M:%S")'- 每次更改并输入新的终端命令时,都会将标题更新为新的日期和时间!格式如下所示:02/06/2020 - 23:32:58小智 5
如果您使用的是 Ubuntu 16.04,您可能需要:
PS1=$
PROMPT_COMMAND=
echo -en "\033]0;New title\a"
Run Code Online (Sandbox Code Playgroud)
我在链接中列出了有关它的更多信息。
| 归档时间: |
|
| 查看次数: |
106342 次 |
| 最近记录: |