about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--doc/ranger.14
-rw-r--r--doc/ranger.pod6
-rw-r--r--ranger/config/rc.conf6
-rw-r--r--ranger/container/settings.py1
-rw-r--r--ranger/gui/ui.py103
5 files changed, 56 insertions, 64 deletions
diff --git a/doc/ranger.1 b/doc/ranger.1
index 5324ccc3..ceb44098 100644
--- a/doc/ranger.1
+++ b/doc/ranger.1
@@ -133,7 +133,7 @@
 .\" ========================================================================
 .\"
 .IX Title "RANGER 1"
-.TH RANGER 1 "ranger-1.9.2" "2019-12-30" "ranger manual"
+.TH RANGER 1 "ranger-1.9.2" "2019-12-31" "ranger manual"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
@@ -1176,7 +1176,7 @@ Requires the python-bidi pip package.
 Set a window title? Updates both the \fI\s-1WM_NAME\s0\fR and \fI\s-1WM_ICON_NAME\s0\fR properties.
 .IP "update_tmux_title [bool]" 4
 .IX Item "update_tmux_title [bool]"
-Set the tmux \fIwindow-name\fR to \*(L"ranger\*(R"?
+Set the tmux/screen \fIwindow-name\fR to \*(L"ranger\*(R"?
 .IP "use_preview_script [bool] <zv>" 4
 .IX Item "use_preview_script [bool] <zv>"
 Use the preview script defined in the setting \fIpreview_script\fR?
diff --git a/doc/ranger.pod b/doc/ranger.pod
index a7f07ffc..b2ce21e1 100644
--- a/doc/ranger.pod
+++ b/doc/ranger.pod
@@ -1266,11 +1266,7 @@ Set a window title? Updates both the I<WM_NAME> and I<WM_ICON_NAME> properties.
 
 =item update_tmux_title [bool]
 
-Set the tmux I<window-name> to "ranger"?
-
-=item update_screen_title [bool]
-
-Set the title to "ranger" in the screen program?
+Set the tmux/screen I<window-name> to "ranger"?
 
 =item use_preview_script [bool] <zv>
 
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index c7af4962..9d08a6a7 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -185,13 +185,9 @@ set display_tags_in_all_columns true
 # Set a title for the window? Updates both `WM_NAME` and `WM_ICON_NAME`
 set update_title false
 
-# Set the tmux window-name to "ranger"?
+# Set the tmux/screen window-name to "ranger"?
 set update_tmux_title true
 
-# Set the title to "ranger" in the screen program?
-
-set update_screen_title true
-
 # Shorten the title if it gets long?  The number defines how many
 # directories are displayed at once, 0 turns off this feature.
 set shorten_title 3
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index 348a8761..7549325a 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -88,7 +88,6 @@ ALLOWED_SETTINGS = {
     'unicode_ellipsis': bool,
     'update_title': bool,
     'update_tmux_title': bool,
-    'update_screen_title': bool,
     'use_preview_script': bool,
     'vcs_aware': bool,
     'vcs_backend_bzr': str,
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 3cb219f1..d2dbb759 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -73,7 +73,7 @@ class UI(  # pylint: disable=too-many-instance-attributes,too-many-public-method
         self.multiplexer = None
         self._draw_title = None
         self._tmux_automatic_rename = None
-        self._tmux_allow_rename = None
+        self._tmux_title = None
         self._screen_title = None
         self.browser = None
 
@@ -96,6 +96,7 @@ class UI(  # pylint: disable=too-many-instance-attributes,too-many-public-method
         self.win.leaveok(0)
         self.win.keypad(1)
         self.load_mode = False
+
         curses.cbreak()
         curses.noecho()
         curses.halfdelay(20)
@@ -120,16 +121,11 @@ class UI(  # pylint: disable=too-many-instance-attributes,too-many-public-method
             self.win.refresh()
             self._draw_title = curses.tigetflag('hs')  # has_status_line
 
-            if 'TMUX' in os.environ:
-                self.multiplexer = 'TMUX'
-            elif os.environ['TERM'] == 'screen':
-                self.multiplexer = 'screen'
-
-            self.handle_multiplexer(self.multiplexer)
-
         self.update_size()
         self.is_on = True
 
+        self.handle_multiplexer()
+
         if 'vcsthread' in self.__dict__:
             self.vcsthread.unpause()
 
@@ -177,8 +173,7 @@ class UI(  # pylint: disable=too-many-instance-attributes,too-many-public-method
             del self.__dict__['vcsthread']
         DisplayableContainer.destroy(self)
 
-        if self.multiplexer is not None:
-            self.handle_multiplexer(self.multiplexer, restore_required=True)
+        self.restore_multiplexer_name()
 
         self.suspend()
 
@@ -471,55 +466,61 @@ class UI(  # pylint: disable=too-many-instance-attributes,too-many-public-method
         else:
             self.titlebar.throbber = string
 
-    # Handles window renaming behaviour of the terminal multiplexers GNU Screen and Tmux
-    def handle_multiplexer(self, multiplexer=None, restore_required=False):
-        # helper function
-        def execute_rename(multiplexer):
-            try:
-                if multiplexer == 'TMUX':
-                    check_output(['tmux', 'set-window-option',
-                                  'automatic-rename', self._tmux_automatic_rename])
-                elif multiplexer == 'screen':
-                    check_output(['screen', '-X', 'title', self._screen_title])
-            except CalledProcessError:
-                pass
-
-        # Stores the screen window name before renaming it
-        # gives out a warning if $TERM is not "screen"
-
-        if multiplexer == 'screen' and not restore_required:
-            if os.environ['TERM'] != 'screen' and 'TMUX' not in os.environ:
-                self.fm.notify(
-                    '$TERM not set to "screen". Automatic window title not applied.', bad=True)
-            try:
-                self._screen_title = check_output(['screen', '-Q', 'title']).strip()
-            except CalledProcessError:
-                self._screen_title = None
-
-        # Stores the automatic-rename setting
-        # prints out a warning if the allow-rename in tmux is not set
-        if multiplexer == 'TMUX' and not restore_required:
-            if self.settings.update_tmux_title:
-                self._tmux_allow_rename = check_output(
-                    ['tmux', 'show-window-option', '-v', 'allow-rename']).strip()
-                if self._tmux_allow_rename == 'off':
-                    self.fm.notify('Warning: allow-rename not set in Tmux!', bad=True)
+    # Handles window renaming behaviour of the terminal multiplexers
+    # GNU Screen and Tmux
+    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-option', '-v', 'automatic-rename']).strip()
-                        if self._tmux_automatic_rename == 'off':
-                            self._tmux_automatic_rename = 'on'
+                            ['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:
-                        self._tmux_automatic_rename = None
+                        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']).strip()
+                except CalledProcessError:
+                    self._screen_title = None
 
-        if multiplexer is not None and not restore_required:
             sys.stdout.write("\033kranger\033\\")
             sys.stdout.flush()
 
-        # Restore window name
-        if multiplexer and restore_required:
-            execute_rename(multiplexer)
+    # Restore window name
+    def restore_multiplexer_name(self):
+        try:
+            if 'TMUX' in os.environ:
+                if self._tmux_automatic_rename:
+                    check_output(['tmux', 'set-window-option',
+                                  'automatic-rename',
+                                  self._tmux_automatic_rename])
+                else:
+                    check_output(['tmux', 'set-window-option', '-u',
+                                  'automatic-rename'])
+                if self._tmux_title:
+                    check_output(['tmux', 'rename-window', self._tmux_title])
+            elif 'screen' in os.environ['TERM'] and self._screen_title:
+                check_output(['screen', '-X', 'title', self._screen_title])
+        except CalledProcessError:
+            self.fm.notify("Could not restore window-name!", bad=True)
 
     def hint(self, text=None):
         self.status.hint = text