Skip to content
Advertisement

PuTTY: Linux window – How to update the window title during a function?

I’m accessing a Linux machine from a Windows 10 PC via PuTTY. I’ve set the PuTTY (Bash) window title to ‘$PWD’ by setting $PS1 as below:

PS1=[33]0;w07][33[1;33m][w]$[33[0m]

This works well – whenever I change the directory in the shell, the title updates straight away:

Enter image description here

However, if I change directory in a function (as below) the title doesn’t update until after the function completes:

function func() {
    cd /share/testing_area/runtests ;
    python Script.py;
}

Enter image description here Enter image description here

Is there a way to get the title to update during the script?

ANSWER: Final version of the script:

function func() {
    cd /share/testing_area/runtests
    export PS1="[e[1;33m][w]$[e[0m]" # Remove title spec from $PS1
    echo -ne "e]2;$PWDa"  # Set title to current values (uses $PWD as w doesn't work for echo
    python Script.py;
    export PS1="[33]0;w07][33[1;33m][w]$[33[0m]" # Re-add title spec to $PS1
}

Advertisement

Answer

You are changing the title by using PuTTY’s automatic title from the prompt. Unfortunately, the prompt will usually take effect once your prompt is visible again, which means not before your function or script ends.

If you want to change the title dynamically I would recommend this solution instead.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement