Skip to content

Instantly share code, notes, and snippets.

@randynobx
Created March 12, 2015 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randynobx/cfcfcb697e97cac73342 to your computer and use it in GitHub Desktop.
Save randynobx/cfcfcb697e97cac73342 to your computer and use it in GitHub Desktop.
Patch for Ranger to reset the parent tmux window name on exit. **Does NOT grab correct name from prior to ranger start, but can be used to hard code a name to reset to
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 3898a7a..2ea5b28 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -6,6 +6,7 @@ import sys
import curses
import _curses
+from subprocess import check_output
from .displayable import DisplayableContainer
from .mouse_event import MouseEvent
from ranger.ext.keybinding_parser import KeyBuffer, KeyMaps, ALT_KEY
@@ -87,6 +88,11 @@ class UI(DisplayableContainer):
self.is_on = True
if self.settings.update_tmux_title:
+ # Grab previous tmux window name for restoration when ranger is closed
+ try:
+ self.tmux_pname = check_output(["tmux", "display-message", "-p", "'#W'"], stderr=open(os.devnull, 'wb'))
+ except subprocess.CalledProcessError:
+ self.tmux_pname = ''
sys.stdout.write("\033kranger\033\\")
sys.stdout.flush()
@@ -122,6 +128,12 @@ class UI(DisplayableContainer):
def destroy(self):
"""Destroy all widgets and turn off curses"""
DisplayableContainer.destroy(self)
+
+ # Reset tmux window name
+ if self.settings.update_tmux_title:
+ sys.stdout.write("\033k" + str(self.tmux_pname) + "\033\\")
+ sys.stdout.flush()
+
self.suspend()
def handle_mouse(self):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment