summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorVitaly Belman <vitaly@telefonica.com>2017-03-17 10:06:53 +0200
committernfnty <git@nfnty.se>2017-03-19 19:03:59 +0100
commitb327b7352e10909d4713d3c802c4c34945523e2b (patch)
tree471e825de36799e2cc9dca38c876838f9f4edc0a /ranger
parenteb4d9d5424ee31ae911876213b7d483f8a90d451 (diff)
downloadranger-b327b7352e10909d4713d3c802c4c34945523e2b.tar.gz
Add ability to save/restore tabs
Fixes #502
Closes #505
Diffstat (limited to 'ranger')
-rw-r--r--ranger/config/rc.conf3
-rw-r--r--ranger/container/settings.py1
-rw-r--r--ranger/core/fm.py7
-rw-r--r--ranger/core/main.py16
4 files changed, 27 insertions, 0 deletions
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 3d58360c..d6652654 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -215,6 +215,9 @@ set clear_filters_on_dir_change false
 # Disable displaying line numbers in main column
 set line_numbers false
 
+# Save tabs on exit
+set save_tabs_on_exit false
+
 # Enable scroll wrapping - moving down while on the last item will wrap around to
 # the top and vice versa.
 set wrap_scroll false
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index df9a45c7..b795d4a9 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -81,6 +81,7 @@ ALLOWED_SETTINGS = {
     'wrap_scroll': bool,
     'xterm_alt_key': bool,
     'clear_filters_on_dir_change': bool,
+    'save_tabs_on_exit': bool,
 }
 
 ALLOWED_VALUES = {
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 53314ff7..f8163a73 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -402,3 +402,10 @@ class FM(Actions,  # pylint: disable=too-many-instance-attributes
                     fobj.write(self.thisdir.path)
             self.bookmarks.remember(self.thisdir)
             self.bookmarks.save()
+
+            # Save tabs
+            if self.settings.save_tabs_on_exit and len(self.tabs) > 1:
+                with open(self.datapath('tabs'), 'a') as fobj:
+                    # Don't save active tab since launching ranger changes the active tab
+                    fobj.write('\0'.join(v.path for t, v in self.tabs.items()
+                                         if t != self.current_tab) + '\0\0')
diff --git a/ranger/core/main.py b/ranger/core/main.py
index b7ad4617..9c066e0b 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -149,6 +149,22 @@ def main(
             if not os.path.exists(args.datadir):
                 os.makedirs(args.datadir)
 
+        # Restore saved tabs
+        tabs_datapath = fm.datapath('tabs')
+        if fm.settings.save_tabs_on_exit and os.path.exists(tabs_datapath) and not args.paths:
+            try:
+                with open(tabs_datapath, 'r') as fobj:
+                    tabs_saved = fobj.read().partition('\0\0')
+                    fm.start_paths += tabs_saved[0].split('\0')
+                if tabs_saved[-1]:
+                    with open(tabs_datapath, 'w') as fobj:
+                        fobj.write(tabs_saved[-1])
+                else:
+                    os.remove(tabs_datapath)
+            except OSError as ex:
+                LOG.error('Unable to restore saved tabs')
+                LOG.exception(ex)
+
         # Run the file manager
         fm.initialize()
         ranger.api.hook_init(fm)