Bash - Update terminal title by running a second command

后端 未结 8 1496
Happy的楠姐
Happy的楠姐 2020-12-24 13:27

On my terminal in Ubuntu, I often run programs which keep running for a long time. And since there are a lot of these programs, I keep forgetting which terminal is for which

8条回答
  •  清酒与你
    2020-12-24 13:34

    Try this:

    trap 'echo -ne "\033]2;$(history 1 | sed "s/^[ ]*[0-9]*[ ]*//g")\007"' DEBUG
    

    Thanks to the history 1 it works even with complicated expressions like:

    true && (false); echo $? | cat
    

    For which approaches relying on $BASH_COMMAND or $@ fail. For example simon's displays:

    true | echo $? | cat
    

    Thanks to Gilles and simon for providing inspiration.

提交回复
热议问题