ofirgall / tmux-window-name

A plugin to name your tmux windows smartly.
MIT License
213 stars 22 forks source link

Unhelpful window title with console file manager ranger #6

Closed kohane27 closed 2 years ago

kohane27 commented 2 years ago

Hello ofirgall!

First, thank you for creating such a useful program. Really happy that I no longer need to manually rename windows.

However, I have a problem with it integrating with ranger. Please see the video below:

https://user-images.githubusercontent.com/57322459/162747412-03e085f4-2304-4167-b5e3-b9f03f07882e.mp4

To reproduce:

  1. type r (my alias for ranger) to open ranger in terminal
  2. current tmux window is not updated (as expected)
  3. move to next window by pressing alt+2
  4. previous tmux window is updated (as expected) but it's renamed as /usr/bin/python -O /

Below is my settings in ranger (if it's relevant):

# Set a title for the window? Updates both `WM_NAME` and `WM_ICON_NAME`
set update_title true

# Set the tmux/screen window-name to "ranger"?
set update_tmux_title true

I've tried disabling tmux-window-name as follows:

# set -g @plugin 'ofirgall/tmux-window-name'

set -g status-interval 1
set -g automatic-rename on
set -g automatic-rename-format '#{b:pane_current_path}'
set -g allow-rename on

This is what happens:

https://user-images.githubusercontent.com/57322459/162747571-ccf76c48-da9b-43ea-9999-8e28091369c2.mp4

It's simply displayed as python (better than /usr/bin/python -O / imo)

However, I simply lose the benefits of using tmux-window-name:

screenshot-2022-04-11-21-02-13

Recommendation

Maybe provide a manual intervention to rename certain programs? Currently I encounter this problem only with ranger. But I'm quite sure there are other programs with similar issues. Is it possible to provide a way to "override manually"? Like a mapping below:

set -g @tmux_window_override '{"/usr/bin/python -O /", "ranger", "undesired window name", "desired window name"}'

Thank you again!

ofirgall commented 2 years ago

Thanks for the detailed issue. I would add @tmux_window_substitute which allows to add regex replace with list of tuples.

By the way I would suggest to turn off update_tmux_title in ranger, it modifies your tmux rename options, it collides with tmux-window-name

kohane27 commented 2 years ago

Thank you so much for such a quick fix enhancement. Really appreciate it. It works like a charm! Btw this is what I get after running --print_programs for ranger:

❯ ~/.tmux/plugins/tmux-window-name/scripts/rename_session_windows.py --print_programs

/usr/bin/python -O /usr/bin/ranger -> ranger

Thanks again!

kohane27 commented 1 year ago

Not sure if this is relevant but I think it might be helpful to some people.

I use ranger along with tmux a lot. When I open ranger, and then open a file in vim, the tmux pane is stuck with the name ranger, which is not helpful. I have the following vim snippet to rename the tmux pane whenever I open a file in vim.

augroup _tmux_rename
  autocmd!
  if exists('$TMUX')
    autocmd BufReadPost,FileReadPost,BufNewFile,BufEnter * call system("tmux rename-window " . expand("%:t"))
  endif
augroup end

We don't need the following

autocmd VimLeave,FocusLost * call system("tmux rename-window \"\"") " to enable auto-rename again

because tmux-window-name takes care for us when we're back to ranger. Cheers!