Set screen-title from shellscript

后端 未结 12 1602
忘掉有多难
忘掉有多难 2020-12-12 16:48

Is it possible to set the Screen Title using a shell script?

I thought about something like sending the key commands ctrl+A shift-

12条回答
  •  [愿得一人]
    2020-12-12 17:55

    Try the below commands, no need to edit any file or configuration like ~/.bashrc, Can be used at runtime.

    Set static text as title: (My Title)

    export PS1='\[\e]0;My Title\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    

    Set local/global variable as title: ($USER)

    export PS1='\[\e]0;$USER\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    

    Set command output as title: (hostname)

    export PS1='\[\e]0;`hostname`\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    

    Set to default (Revert back):

    export PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    

提交回复
热议问题