PuTTY:Linux window - 如何在函数期间更新 window 标题?
PuTTY: Linux window - How to update the window title during a function?
我正在通过 PuTTY 从 Windows 10 PC 访问 Linux 机器。我通过如下设置 $PS1 将 PuTTY (Bash) window 标题设置为“$PWD”:
PS1=\[3]0;\w[=13=]7\]\[3[1;33m\][\w]$\[3[0m\]
效果很好——每当我更改 shell 中的目录时,标题都会立即更新:
但是,如果我在函数中更改目录(如下所示),则在函数完成后标题才会更新:
function func() {
cd /share/testing_area/runtests ;
python Script.py;
}
有没有办法让标题在脚本期间更新?
答案:脚本的最终版本:
function func() {
cd /share/testing_area/runtests
export PS1="\[\e[1;33m\][\w]$\[\e[0m\]" # Remove title spec from $PS1
echo -ne "\e]2;$PWD\a" # Set title to current values (uses $PWD as \w doesn't work for echo
python Script.py;
export PS1="\[3]0;\w[=15=]7\]\[3[1;33m\][\w]$\[3[0m\]" # Re-add title spec to $PS1
}
您正在使用提示中的 PuTTY 自动标题更改标题。不幸的是,提示通常会在您的提示再次可见后生效,这意味着不会在您的函数或脚本结束之前。
如果您想动态更改标题,我建议您 this solution instead。
我正在通过 PuTTY 从 Windows 10 PC 访问 Linux 机器。我通过如下设置 $PS1 将 PuTTY (Bash) window 标题设置为“$PWD”:
PS1=\[3]0;\w[=13=]7\]\[3[1;33m\][\w]$\[3[0m\]
效果很好——每当我更改 shell 中的目录时,标题都会立即更新:
但是,如果我在函数中更改目录(如下所示),则在函数完成后标题才会更新:
function func() {
cd /share/testing_area/runtests ;
python Script.py;
}
有没有办法让标题在脚本期间更新?
答案:脚本的最终版本:
function func() {
cd /share/testing_area/runtests
export PS1="\[\e[1;33m\][\w]$\[\e[0m\]" # Remove title spec from $PS1
echo -ne "\e]2;$PWD\a" # Set title to current values (uses $PWD as \w doesn't work for echo
python Script.py;
export PS1="\[3]0;\w[=15=]7\]\[3[1;33m\][\w]$\[3[0m\]" # Re-add title spec to $PS1
}
您正在使用提示中的 PuTTY 自动标题更改标题。不幸的是,提示通常会在您的提示再次可见后生效,这意味着不会在您的函数或脚本结束之前。
如果您想动态更改标题,我建议您 this solution instead。