From a5767f170319c0b7043c4e09c9e35331f15dcd29 Mon Sep 17 00:00:00 2001 From: toonn Date: Tue, 30 Jan 2018 15:05:43 +0100 Subject: Guard tmux title changes Changing the tmux window title to "ranger" was not guarded for the presence of the tmux executable, this tripped up at least one user with an `rc.conf` that still `set update_tmux_title true`. While the behavior is *not-a-bug*, I expect most people'd rather have the setting enabled by default since "python" is a less useful window title. Fix #1042 --- examples/rc_emacs.conf | 2 +- ranger/config/rc.conf | 2 +- ranger/gui/ui.py | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/rc_emacs.conf b/examples/rc_emacs.conf index 26074a42..8924d1d6 100644 --- a/examples/rc_emacs.conf +++ b/examples/rc_emacs.conf @@ -129,7 +129,7 @@ set display_tags_in_all_columns true set update_title false # Set the title to "ranger" in the tmux program? -set update_tmux_title false +set update_tmux_title true # Shorten the title if it gets long? The number defines how many # directories are displayed at once, 0 turns off this feature. diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf index 38e6f11e..39240b06 100644 --- a/ranger/config/rc.conf +++ b/ranger/config/rc.conf @@ -144,7 +144,7 @@ set display_tags_in_all_columns true set update_title false # Set the title to "ranger" in the tmux program? -set update_tmux_title false +set update_tmux_title true # Shorten the title if it gets long? The number defines how many # directories are displayed at once, 0 turns off this feature. diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 990db0ad..4446cb29 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -9,6 +9,7 @@ import threading import curses from subprocess import CalledProcessError +from ranger.ext.get_executables import get_executables from ranger.ext.keybinding_parser import KeyBuffer, KeyMaps, ALT_KEY from ranger.ext.lazy_property import lazy_property from ranger.ext.signals import Signal @@ -113,7 +114,7 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method self._draw_title = curses.tigetflag('hs') # has_status_line # Save tmux setting `automatic-rename` - if self.settings.update_tmux_title: + if self.settings.update_tmux_title and 'tmux' in get_executables(): try: self._tmux_automatic_rename = check_output( ['tmux', 'show-window-options', '-v', 'automatic-rename']).strip() @@ -123,7 +124,7 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method self.update_size() self.is_on = True - if self.settings.update_tmux_title: + if self.settings.update_tmux_title and 'tmux' in get_executables(): sys.stdout.write("\033kranger\033\\") sys.stdout.flush() @@ -172,7 +173,7 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method DisplayableContainer.destroy(self) # Restore tmux setting `automatic-rename` - if self.settings.update_tmux_title: + if self.settings.update_tmux_title and 'tmux' in get_executables(): if self._tmux_automatic_rename: try: check_output(['tmux', 'set-window-option', -- cgit 1.4.1-2-gfad0 From b8a2311bd72f39d2adf4bc0c365c3c22e0ec3897 Mon Sep 17 00:00:00 2001 From: toonn Date: Wed, 31 Jan 2018 23:30:51 +0100 Subject: Only try changing the tmux title if inside tmux Check whether we're running in `tmux` by checking the existence of `$TMUX` and only if so set the window title. --- ranger/gui/ui.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 4446cb29..4f76dfab 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -9,7 +9,6 @@ import threading import curses from subprocess import CalledProcessError -from ranger.ext.get_executables import get_executables from ranger.ext.keybinding_parser import KeyBuffer, KeyMaps, ALT_KEY from ranger.ext.lazy_property import lazy_property from ranger.ext.signals import Signal @@ -114,7 +113,7 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method self._draw_title = curses.tigetflag('hs') # has_status_line # Save tmux setting `automatic-rename` - if self.settings.update_tmux_title and 'tmux' in get_executables(): + if self.settings.update_tmux_title and 'TMUX' in os.environ: try: self._tmux_automatic_rename = check_output( ['tmux', 'show-window-options', '-v', 'automatic-rename']).strip() @@ -124,7 +123,7 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method self.update_size() self.is_on = True - if self.settings.update_tmux_title and 'tmux' in get_executables(): + if self.settings.update_tmux_title and 'TMUX' in os.environ: sys.stdout.write("\033kranger\033\\") sys.stdout.flush() @@ -173,7 +172,7 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method DisplayableContainer.destroy(self) # Restore tmux setting `automatic-rename` - if self.settings.update_tmux_title and 'tmux' in get_executables(): + if self.settings.update_tmux_title and 'TMUX' in os.environ: if self._tmux_automatic_rename: try: check_output(['tmux', 'set-window-option', -- cgit 1.4.1-2-gfad0