我已经在这里问过了,但没有得到我想要的答案:https://unix.stackexchange.com/questions/457997/automate-the-title-of-gnu-screen-windows
我尝试使屏幕上的窗口标题自动等于在此窗口中打开的文件(或目录)。举例来说,我正在处理放置在〜/ desktop / project / src / views / 中的 file.pug 文件,我希望标题为< em>〜/ desktop / project / src / views / file.pug ,但这只是〜/ desktop / project / src / views /
我发现了这一点:https://unix.stackexchange.com/questions/6065/gnu-screen-new-window-name-change通过修改.zshrc文件提供了一种完成某些事情的方式,这解释了为什么.zshrc中的脚本被Screen监听的原因与打开< em>迅速扩展(对我来说是个谜),它来自info screen -n 'Dynamic Titles'
,它表示:
you must modify your shell prompt to output a null title-escape-sequence (<ESC> k <ESC> \) as a part of your prompt. The last part of your prompt must be the same as the string you specified for the search portion of the title. Once this is set up, screen will use the title-escape-sequence to clear the previous command name and get ready for the next command. Then, when a newline is received from the shell, a search is made for the end of the prompt. If found, it will grab the first word after the matched string and use it as the command name.
但是该脚本仅打印文件夹路径,而不打印文件,而且我不了解所解释的内容,因此我无法适应我的需要:不仅打印目录,而且打印工作文件
到目前为止,我对.zshrc文件的脚本的了解:
precmd () {
local tmp='%~'
local HPWD=${(%)tmp}
if [[ $TERM == screen* ]]; then
printf '\ek%s\e\\' $HPWD
fi
}
-precmd ()
是在每个提示之前执行的功能(也可以是chpwd())(src:http://tldp.org/HOWTO/Xterm-Title-4.html)
-local
表示变量具有局部作用域(src:How do I keep functions/variables local to my zshrc?)
-precmd () {local HPWD=${(%)-%~}
(应等效于第2行和第3行)打开当前工作目录(但目录中没有文件)的提示扩展
-if [[ $TERM == screen* ]]; then printf
(如果正在运行软件屏幕,则打印...
-'\ek%s\e\\'
不知道是什么意思