joouha / ranger_tmux

Tmux integration for ranger
MIT License
37 stars 5 forks source link

invalid literal for int() with base 10. Probably tmux version incompatibility. #3

Closed 4l1fe closed 2 years ago

4l1fe commented 2 years ago

The plugin installed properly. After trying to execute a command or set a flag i got such the error.

22:38:30 ERRO invalid literal for int() with base 10: ''
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ranger/core/actions.py", line 271, in execute_console
    cmd.execute()
  File "/home/user/.local/lib/python3.8/site-packages/ranger_tmux/cwd_sync.py", line 16, in execute
    pane_id = util.select_shell_pane(self.ranger_pane)
  File "/home/user/.local/lib/python3.8/site-packages/ranger_tmux/util.py", line 72, in select_shell_pane
    has_marked_pane = int(
ValueError: invalid literal for int() with base 10: ''

The problem is there is no variable "#{window_marked_flag}". Current format window variables:

     window_active                   1 if window active
     window_activity                 Time of window last activity
     window_activity_flag            1 if window has activity
     window_bell_flag                1 if window has bell
     window_bigger                   1 if window is larger than client
     window_end_flag                 1 if window has the highest index
     window_flags           #F       Window flags
     window_format                   1 if format is for a window (not assuming the current)
     window_height                   Height of window
     window_id                       Unique window ID
     window_index           #I       Index of window
     window_last_flag                1 if window is the last used
     window_layout                   Window layout description, ignoring zoomed window panes
     window_linked                   1 if window is linked across sessions
     window_name            #W       Name of window
     window_offset_x                 X offset into window if larger than client
     window_offset_y                 Y offset into window if larger than client
     window_panes                    Number of panes in window
     window_silence_flag             1 if window has silence alert
     window_stack_index              Index in session most recent stack
     window_start_flag               1 if window has the lowest index
     window_visible_layout           Window layout description, respecting zoomed window panes
     window_width                    Width of window
     window_zoomed_flag              1 if window is zoomed
     wrap_flag                       Pane wrap flag
❯ tmux -V
tmux 3.0a

May be in the older or newer versions the variable exists, i didn't check it.

I fixed it easily and can make a Pull Request, don't you mind about it? Simply changed definition of the has_marked_pane variable

from

    has_marked_pane = int(
        tmux("display", "-p", "-F", "#{window_marked_flag}", "-t", ranger_pane)
    )

to

    marks = tmux("display", "-p", "-F", "#{window_flags}", "-t", ranger_pane)
    # marks var contains for instance the following symbols "*MZ" or "*" if empty
    has_marked_pane = 'M' in marks
4l1fe commented 2 years ago

Haha, i've just noticed you have the Jupiter avatar as me =)

joouha commented 2 years ago

Hi,

Thanks for looking into this. It looks like the window_marked_flag was added in tmux==3.1 (see here).

I'd be happy if you'd like to submit your PR - it would be nice to support older versions of tmux.