Created
March 12, 2015 02:21
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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