Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keep terminal window title when using screen

Whenever I start screen, it changes the title of the terminal window to 'screen'. Can I prevent that and have the window title remain what it would be if I hadn't run my command under screen?

More specifically, I'd like gnome-terminal to display the name of the buffer I'm editing in vim. I can do this by adding set title to my .vimrc. Now when I run vim, the buffer name (along with some other information), shows up in the title of gnome-terminal. When I start screen and run vim, the title changes to 'screen'.

I've looked at the following page:

http://beautifulpixels.blogspot.co.at/2012/01/automatic-screen-window-titles-in-bash.html

But the suggested solution places the window title in the screen status line. I also tried adding this:

case $TERM in
    screen*)
        # http://dtfm.tumblr.com/post/7193076007/the-sweetest-screenrc-hack-ever
        SCREENTITLE='\[\ek\e\\\]\[\ek\W\e\\\]'
        ;;
    *)
        SCREENTITLE=''
        ;;
esac

TITLEBAR='\[\e]0;\a\]'

export PS1="${SCREENTITLE}${TITLEBAR}[\u@\h \W]\$ "

To my .bashrc, but this only sets the window title to the current directory. Even if I run vim, the window title remains the current working directory. This is not the case if I run it outside of screen.

Any ideas?

like image 496
juniper- Avatar asked Aug 22 '26 16:08

juniper-


1 Answers

Although I didn't exactly solve it, demure's comment enticed me to check out tmux. Using that I was able to put the following line:

autocmd BufReadPost,FileReadPost,BufNewFile * call system("tmux rename-window '" . expand("%:p:~") . " - VIM'")

In my .vimrc file and I get the effect I wanted in the first place (except, of course, now I'm using tmux).

References:

tmux tabs with name of file open in vim

How can I expand the full path of the current file to pass to a command in Vim?

like image 191
juniper- Avatar answered Aug 25 '26 10:08

juniper-



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!