Score:3

How to remove index numbers and symbols from tmux window titles

fr flag

This configuration removes index numbers and other symbols from tmux's window titles to prioritize readability. It results in the following format:

basePath/      -> at the terminal prompt

fileName       -> inside Vim

It comes mostly from this StackOverflow post.


Score:2
fr flag

~/.tmux.conf

Allow window titles to be renamed by our .vimrc and .bash_aliases config files below and set the title format to only show the name.

See the tmux man page for more options under "FORMATS" and "Variable name". For example, to keep the index number, you would change the window-status-format and window-status-current-format lines to "#I:#W".

set -g allow-rename on
set-window-option -g window-status-format "#W"
set-window-option -g window-status-current-format "#W"

Specific to a configuration without index numbers, you can set your tab creation and movement bindings to be more browser- and Vim-like.

# Create window -- Ctrl + t 
# Navigate windows -- Ctrl+ h,l 
bind -n C-t new-window
bind -n C-h previous-window
bind -n C-l next-window

~/.vimrc

Set the window title to the filename when entering Vim and saving a file.

if exists('$TMUX')
    autocmd VimEnter,BufWrite * call system("tmux rename-window ' " . expand("%:t") . " '")
endif


~/.bash_aliases

I used bash instead of the automatic-rename options in tmux so that the window title would be renamed to the active pane, if applicable. I also rename titles back to the basepath on exiting Vim here.

# If Tmux running...
tmux ls > /dev/null 2>&1
TMUX_STATUS=$?
if [ $TMUX_STATUS -eq 0 ]; then

    # Create function to get pwd, trim to "basepath/", 
    # and rename window
    basepathTitle () {
        getval=$(pwd)
        BASEPATH_TITLE=" ${getval##*/}/ "
        tmux rename-window "$BASEPATH_TITLE"
    }

    # Change cd functionality to rename window title to
    # pwd after every directory change
    cd () {

        builtin cd "$@"
        CD_STATUS=$?

        basepathTitle

        return "$CD_STATUS"
    }

    # Change vim functionality to change title 
    # back to basepath on close
    vim () {
        
        /usr/bin/vim "$@"
        VIM_STATUS=$?
        
        basepathTitle

        return "$VIM_STATUS"
    }

    # Set window title when tmux starts
    basepathTitle

fi

Source tmux.conf
tmux source-file ~/.tmux.conf

Source .bashrc
. .bashrc

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.