在屏幕下运行时,当前目录不会出现在标题栏中

发布于 2024-07-25 21:24:39 字数 574 浏览 4 评论 0原文

我的 .tcshrc 中的 xterm $prompt 变量是:

set prompt="%{\033]0;%m:%~\007%}%{^[[;37;1m%}%B%{^[[;34;1m%}%m%{^[[;34;1m%}:%b%c%# "

上面的突出显示部分(%{\033]0;%m:%~\007%}) 放置主机名 (%m) 和当前目录(%~) 在标题栏中。 (至少我认为这就是将其放在标题栏中的原因;自从我摆弄这个提示以来已经有一段时间了)。

但是,当我运行 screen 时,当我更改目录时,当前目录会停止更新。

我的问题:

  1. 如何让这个提示在屏幕上起作用?
  2. 有没有更好的方法在标题栏中显示当前目录?

我正在使用 xterm 和 tcsh 运行 linux。

My xterm $prompt variable in my .tcshrc is:

set prompt="%{\033]0;%m:%~\007%}%{^[[;37;1m%}%B%{^[[;34;1m%}%m%{^[[;34;1m%}:%b%c%# "

The highlighted part above (%{\033]0;%m:%~\007%}) puts the hostname (%m) and the current directory (%~) in the title bar. (At least I think that that's what puts it in the title bar; it's been a while since I fiddled with this prompt).

When I run screen, however, the current directory stops getting updated when I change directories.

My questions:

  1. How can I make this prompt work in screen?
  2. Is there a better way to display the current directory in the title bar?

I am running linux with xterm and tcsh.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

⊕婉儿 2024-08-01 21:24:39

我认为由于屏幕的工作方式,没有直接的方法。 但是 screen 可以显示自己的状态栏,您可以在 .screenrc 中定义该状态栏。 以我的为例:

hardstatus alwayslastline
 hardstatus string '%{= kG}[ %{G}%H %{g}][%=%{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'

I think there is no direct way, because of the way screen works. However screen can display its own status bar, that you can define in .screenrc. Here's mine for instance :

hardstatus alwayslastline
 hardstatus string '%{= kG}[ %{G}%H %{g}][%=%{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
绮烟 2024-08-01 21:24:39

首先,要使其正常工作,您必须检查 .tcshrcsetprompt=blah-blah 的行到底在哪里。 例如,下面的代码在纯 xterm 中完美运行不会在 xterm 的 screen 下运行:

switch ($TERM)
case "xterm*":
  set prompt="%{\033]0;${HOME:t}@%m:%l:%c08\007%}%{\033[36m%}%l:%c02%#%{\033[0m%} "
  # update xterm title to display current cmd in it
  alias postcmd 'echo -n "\033]0;${HOME:t}@`hostname`:${tty}    \!#:q\007"'
...

因为 screen 默认情况下将 $TERM 变量设置为 screen 而不是 xterm! 所以你必须添加:

case "screen":
  # lame, but prevents an error in screen after 'su - root'
  if (! $?WINDOW) setenv WINDOW 1
  set prompt="%{\033]0;${HOME:t}@%m:${WINDOW}:%c08\007%}%{\033[36m%}%c02%#%{\033[0m%} "
  alias postcmd 'echo -n "\033]0;${HOME:t}@`hostname`:${WINDOW}    \!#:q\007"'
  ...

其次,确保~/.screenrc中有这一行:

termcapinfo xterm* 'hs:ts=\E]2;:fs=\007:ds=\E]2;\007'

Firstly, to make it work you must check where exactly is the line with set prompt=blah-blah in your .tcshrc. For example, the code below that perfectly works in plain xterm would not work under screen in xterm:

switch ($TERM)
case "xterm*":
  set prompt="%{\033]0;${HOME:t}@%m:%l:%c08\007%}%{\033[36m%}%l:%c02%#%{\033[0m%} "
  # update xterm title to display current cmd in it
  alias postcmd 'echo -n "\033]0;${HOME:t}@`hostname`:${tty}    \!#:q\007"'
...

because screen by default sets $TERM variable to screen and not xterm! So you must add:

case "screen":
  # lame, but prevents an error in screen after 'su - root'
  if (! $?WINDOW) setenv WINDOW 1
  set prompt="%{\033]0;${HOME:t}@%m:${WINDOW}:%c08\007%}%{\033[36m%}%c02%#%{\033[0m%} "
  alias postcmd 'echo -n "\033]0;${HOME:t}@`hostname`:${WINDOW}    \!#:q\007"'
  ...

Secondly, make sure yo have this line in ~/.screenrc:

termcapinfo xterm* 'hs:ts=\E]2;:fs=\007:ds=\E]2;\007'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文