# Buggy code
def handle_multiplexer(self):
    if self.settings.update_tmux_title:
        if "TMUX" in os.environ:
            # Stores the automatic-rename setting
            # prints out a warning if the allow-rename in tmux is not set
            tmux_allow_rename = check_output(
                ["tmux", "show-window-options", "-v", "allow-rename"]
            ).strip()
            if tmux_allow_rename == "off":
                self.fm.notify("Warning: allow-rename not set in Tmux!", bad=True)
            elif self._tmux_title is None:
                self._tmux_title = check_output(
                    ["tmux", "display-message", "-p", "#W"]
                ).strip()
            else:
                try:
                    self._tmux_automatic_rename = check_output(
                        ["tmux", "show-window-options", "-v", "automatic-rename"]
                    ).strip()
                    if self._tmux_automatic_rename == "on":
                        check_output(
                            ["tmux", "set-window-option", "automatic-rename", "off"]
                        )
                except CalledProcessError:
                    pass
        elif "screen" in os.environ["TERM"] and self._screen_title is None:
            # Stores the screen window name before renaming it
            # gives out a warning if $TERM is not "screen"
            try:
                self._screen_title = check_output(
                    ["screen", "-Q", "title"], shell=True
                ).strip()
            except CalledProcessError:
                self._screen_title = None

        sys.stdout.write("\033kranger\033\\")
        sys.stdout.flush()


# Traceback (FileNotFoundError)
ranger version: ranger 1.9.3
Python version: 3.7.3 (default, Apr  3 2019, 05:39:12) [GCC 8.2.0]
Locale: en_US.UTF-8

Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/ranger/core/main.py", line 171, in main
fm.initialize()
File "/home/pi/.local/lib/python3.7/site-packages/ranger/core/fm.py", line 132, in initialize
self.ui.initialize()
File "/home/pi/.local/lib/python3.7/site-packages/ranger/gui/ui.py", line 127, in initialize
self.handle_multiplexer()
File "/home/pi/.local/lib/python3.7/site-packages/ranger/gui/ui.py", line 500, in handle_multiplexer
['screen', '-Q', 'title']).strip()
File "/home/pi/.local/lib/python3.7/site-packages/ranger/ext/spawn.py", line 35, in check_output
process = Popen(popenargs, stderr=fd_devnull, **kwargs)
File "/usr/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'screen': 'screen'

ranger crashed. Please report this traceback at:
https://github.com/ranger/ranger/issu

# Fixed code
def handle_multiplexer(self):
    if self.settings.update_tmux_title and not self._multiplexer_title:
        try:
            if _in_tmux():
                # Stores the automatic-rename setting
                # prints out a warning if allow-rename isn't set in tmux
                try:
                    tmux_allow_rename = check_output(
                        ["tmux", "show-window-options", "-v", "allow-rename"]
                    ).strip()
                except CalledProcessError:
                    tmux_allow_rename = "off"
                if tmux_allow_rename == "off":
                    self.fm.notify("Warning: allow-rename not set in Tmux!", bad=True)
                else:
                    self._multiplexer_title = check_output(
                        ["tmux", "display-message", "-p", "#W"]
                    ).strip()
                    self._tmux_automatic_rename = check_output(
                        ["tmux", "show-window-options", "-v", "automatic-rename"]
                    ).strip()
                    if self._tmux_automatic_rename == "on":
                        check_output(
                            ["tmux", "set-window-option", "automatic-rename", "off"]
                        )
            elif _in_screen():
                # Stores the screen window name before renaming it
                # gives out a warning if $TERM is not "screen"
                self._multiplexer_title = check_output(
                    ["screen", "-Q", "title"]
                ).strip()
        except CalledProcessError:
            self.fm.notify(
                "Couldn't access previous multiplexer window"
                " name, won't be able to restore.",
                bad=False,
            )
        if not self._multiplexer_title:
            self._multiplexer_title = os.environ.get("SHELL", "shell").split("/")[-1]

        sys.stdout.write("\033kranger\033\\")
        sys.stdout.flush()