如何更改 gnome 终端配置文件中的标题

如何更改 gnome 终端配置文件中的标题

我知道如何加载特定的终端配置文件以及加载终端读取的配置文件,但每次我尝试设置标题并保存配置文件时,它仍然返回默认值。

我只能更改该会话的窗口标题,并且只能在菜单中更改。如果我尝试类似的操作gnome-terminal --title="MyTerminal"会打开一个终端,但标题仍为默认值。

如何从命令行和配置文件中更改标题?

答案1

看看 gome-terminal 的工作方式,看起来你需要做几件事:

  1. 创建一个新的配置文件,进入编辑 -> 当前配置文件 -> 标题和命令
  2. 选择保留/前置/附加 shell 提供的标题的选项(以适应)
  3. 运行命令 gnome-terminal --title="Wheeee" --profile="新配置文件"

看起来配置文件保存实际上是为了会话保存(即它存储所有打开的窗口),并且它不保存任何命令行提供的标题,因此您可以通过命令行+配置文件获得您想要的内容,但不是通过配置文件。

我冒昧地报告了 GT 的 save-config 开关中缺少命令行选项保存的情况https://bugzilla.gnome.org/show_bug.cgi?id=645207

答案2

这是我很久以前写的脚本,今天仍在使用,用于修改您的 nx 动态标题栏。我仍然不知道如何动态更改配置文件。也许这会有所帮助。该脚本的标题应为 wlabel 才能最好地工作。查看示例

#!/usr/bin/perl
## Copyright (c) 1995, Tim McCoy, Santa Barbara, CA 93111
## Free use and distribution is granted.  Please retain Credits & history
## hplabel (Original name. So named because it was originally created
## for hpterm windows; later modified for sun and linux)
## V 1.0 simple perl script to change an hpterm, xterm, or openlook title
## and icon name to the current directory or as offered on command line.
## V 1.1 Add dtterm, same as xterm (Thanks to Bill Bennett HP-USA)
## V 1.2 renamed to wlabel for Company/personal use.
## V 1.3 Added environmental variable THISWINDOWLABEL detect to retain
##       a window variable regardless of movement 5/1/2000 TAM
## V 1.4 Finally got around to testing openlook; it doesn't work. Commented
## V 1.5 Fix for openbook supplied by Bill Wagner (ecad.rsc.raytheon.com)
## V 1.6 Cool one line addition to permit/use backticks in THISWINDOWLABEL syntax
&usage if ("@ARGV" =~ /\-[(h|H)]+/);

# print "@ARGV\n";
use Cwd;
my $cwd = &cwd();
$text = (@ARGV) ? "@ARGV" : ($ENV{THISWINDOWLABEL}) ? $ENV{THISWINDOWLABEL} : $cwd ; 
$text =~ s/\n//g; # avoid chomp by converting '\n' to nil (why ??)
$text = `/bin/echo "$text"` if ($text =~ /\`/);  # cool one line change
chomp $text;
exit if (! $text);
## print STDERR "text='$text' cwd='$cwd'\n";
$term = $ENV{"TERM"};                           # determine term type
if ($term =~ /^(xterm|dtterm)$/i)
  {
  printf "%c]2;%s%c", 27, $text, 7;             # modify the window name
  printf "%c]1;%s%c", 27, $text, 7;             # modify the icon name
  }
elsif ($term eq "hpterm")
  {
  $len = length($text);                         # determine length
  printf "%c&f0k%dD%s", 27, $len, $text;        # modify the window name
  printf "%c&f-1k%dD%s", 27, $len, $text;       # modify the icon name
  }
elsif ($term =~/^(openlook|sun-cmd)$/i)
  {
  printf "%c]l%s%c\\", 27, "$text", 27 ;        # modify the window name
  printf "%c]L%s%c\\", 27, "$text", 27;         # modify the icon name
  }

## This script doesn't need anything else but I use the following alias
## to automatically generate my location to the current window.
## alias cd 'cd \!* ; wlabel'

sub usage
  {
  print '
  Simple little script to put the current working directory in
  the window banner and icon titles.  Replaces the useless
  "Terminal" or "Xterm" text to useful information.  When used
  with a cd alias, it performs this function automatically.

  usage: wlabel [{string}]

  Without arguments wlabel generates the current working directory
  name into the banner/icon.  When followed by a plain text string 
  the string is placed in the banner/icon name.  Additionally, if
  the environmental variable THISWINDOWLABEL is set to a value then
  THAT variables contents will be used for the label.  V1.6 adds
  permitting backticks in the THISWINDOWLABEL string. (i.e.; 
  setenv THISWINDOWLABEL '."'`hostname`:`pwd` `date +\"%T\"`'".'
  will yield something like: "myhost:/net/myhome/dir 08:40:07"

  examples:

  % wlabel
  # banner/icon is "/your/current/working/directory"
  % wlabel verilog
  # banner/icon is "verilog"
  % setenv THISWINDOWLABEL "common window"
  # banner/icon still says "verilog"
  % wlabel
  # banner/icon is "common window"

  bugs:

  Telnet windows to other machines will NOT update the banners.
  In fact if the cd alias (described below) is used during a telnet
  session it may generate errors if the wlabel utility is not in the path.
  ( If so then just "unalias cd" )

  alias:

  put this alias in your .cshrc file to automate wlabel:
  % alias cd "cd \!* ; ~/bin/wlabel";

  And, if the icon text does NOT expand to the full label name when
  the cursor passes over it, try adding this to your .Xdefaults file:
  Dtfile*desktopIcon:     large
  I think this is the one I set to make it work right.  (TAM 7/3/01)
  ';
  exit 0;
}

答案3

我刚刚在这里回答了一个非常相似的问题:https://askubuntu.com/questions/30988/how-do-you-set-the-title-of-the-active-gnome-terminal-from-the-command-line/31004#31004

基本上,您可以在 ~/.bashrc 文件中设置标题,但您需要更改 PS1 环境变量,以便它不会通过自动设置标题/图标名称本身来覆盖您。查看我在那里发布的说明,如果您无法从那里弄清楚,或者遇到任何问题,请告诉我,我将引导您完成它。

答案4

我正在运行 Ubuntu 14.04,并且必须根据 MiGrieves 的建议执行 1 个额外步骤,我在此处阅读了该建议 -https://askubuntu.com/a/387313 简而言之,我必须转到“编辑”->“配置文件首选项”->“标题和命令”,然后在下拉列表中选择“保留初始标题”。不过,我将“终端”留在了“初始标题”字段中。

相关内容