summary refs log tree commit diff stats
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
parenteb4d9d5424ee31ae911876213b7d483f8a90d451 (diff)
downloadranger-b327b7352e10909d4713d3c802c4c34945523e2b.tar.gz
Add ability to save/restore tabs
Fixes #502
Closes #505
-rw-r--r--doc/ranger.17
-rw-r--r--doc/ranger.pod6
-rw-r--r--doc/rifle.12
-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
7 files changed, 40 insertions, 2 deletions
diff --git a/doc/ranger.1 b/doc/ranger.1
index 402fb598..ed41966d 100644
--- a/doc/ranger.1
+++ b/doc/ranger.1
@@ -129,7 +129,7 @@
 .\" ========================================================================
 .\"
 .IX Title "RANGER 1"
-.TH RANGER 1 "ranger-1.9.0b5" "2017-02-19" "ranger manual"
+.TH RANGER 1 "ranger-1.9.0b5" "2017-03-19" "ranger manual"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
@@ -892,6 +892,11 @@ Enable this if key combinations with the Alt Key don't work for you.
 .IP "clear_filters_on_dir_change [bool]" 4
 .IX Item "clear_filters_on_dir_change [bool]"
 If set to 'true', persistent filters would be cleared upon leaving the directory
+.IP "save_tabs_on_exit [bool]" 4
+.IX Item "save_tabs_on_exit [bool]"
+Save all tabs, except the active, on exit? The last saved tabs are restored once
+when starting the next session. Multiple sessions are stored in a stack and the
+oldest saved tabs are restored first.
 .SH "COMMANDS"
 .IX Header "COMMANDS"
 You can enter the commands in the console which is opened by pressing \*(L":\*(R".
diff --git a/doc/ranger.pod b/doc/ranger.pod
index bb30fab3..8fd499cf 100644
--- a/doc/ranger.pod
+++ b/doc/ranger.pod
@@ -911,6 +911,12 @@ Enable this if key combinations with the Alt Key don't work for you.
 
 If set to 'true', persistent filters would be cleared upon leaving the directory
 
+=item save_tabs_on_exit [bool]
+
+Save all tabs, except the active, on exit? The last saved tabs are restored once
+when starting the next session. Multiple sessions are stored in a stack and the
+oldest saved tabs are restored first.
+
 =back
 
 
diff --git a/doc/rifle.1 b/doc/rifle.1
index e5fe737c..b5146dd9 100644
--- a/doc/rifle.1
+++ b/doc/rifle.1
@@ -129,7 +129,7 @@
 .\" ========================================================================
 .\"
 .IX Title "RIFLE 1"
-.TH RIFLE 1 "rifle-1.9.0b5" "2017-02-19" "rifle manual"
+.TH RIFLE 1 "rifle-1.9.0b5" "2017-03-19" "rifle manual"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
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)