summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@hut.pm>2017-10-01 12:24:18 +0200
committerhut <hut@hut.pm>2017-10-01 12:24:18 +0200
commit0ea94c81a2dff42c28e2655e5ba7987dc78f55be (patch)
treeab3c27e9cf12467fb35ca3069019bdf875d8a658 /ranger
parentfec819a1a7b33811148750760879b5ee3ab0a0e0 (diff)
downloadranger-0ea94c81a2dff42c28e2655e5ba7987dc78f55be.tar.gz
Add option 'save_backtick_bookmark', fixes #947
Diffstat (limited to 'ranger')
-rw-r--r--ranger/config/rc.conf4
-rw-r--r--ranger/container/bookmarks.py17
-rw-r--r--ranger/container/settings.py1
-rw-r--r--ranger/core/fm.py6
4 files changed, 26 insertions, 2 deletions
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 92428312..27c094a1 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -167,6 +167,10 @@ set padding_right true
 # When false, bookmarks are saved when ranger is exited.
 set autosave_bookmarks true
 
+# Save the "`" bookmark to disk.  This can be used to switch to the last
+# directory by typing "``".
+set save_backtick_bookmark true
+
 # You can display the "real" cumulative size of directories by using the
 # command :get_cumulative_size or typing "dc".  The size is expensive to
 # calculate and will not be updated automatically.  You can choose
diff --git a/ranger/container/bookmarks.py b/ranger/container/bookmarks.py
index cba07367..e470a486 100644
--- a/ranger/container/bookmarks.py
+++ b/ranger/container/bookmarks.py
@@ -28,7 +28,8 @@ class Bookmarks(FileManagerAware):
     autosave = True
     load_pattern = re.compile(r"^[\d\w']:.")
 
-    def __init__(self, bookmarkfile, bookmarktype=str, autosave=False):
+    def __init__(self, bookmarkfile, bookmarktype=str, autosave=False,
+            nonpersistent_bookmarks=()):
         """Initializes Bookmarks.
 
         <bookmarkfile> specifies the path to the file where
@@ -39,6 +40,7 @@ class Bookmarks(FileManagerAware):
         self.original_dict = {}
         self.path = bookmarkfile
         self.bookmarktype = bookmarktype
+        self.nonpersistent_bookmarks=set(nonpersistent_bookmarks)
 
     def load(self):
         """Load the bookmarks from path/bookmarks"""
@@ -174,7 +176,8 @@ class Bookmarks(FileManagerAware):
             self.fm.notify('Bookmarks error: {0}'.format(str(ex)), bad=True)
             return
         for key, value in self.dct.items():
-            if isinstance(key, str) and key in ALLOWED_KEYS:
+            if isinstance(key, str) and key in ALLOWED_KEYS \
+                    and key not in self.nonpersistent_bookmarks:
                 fobj.write("{0}:{1}\n".format(str(key), str(value)))
         fobj.close()
 
@@ -189,6 +192,16 @@ class Bookmarks(FileManagerAware):
 
         self._update_mtime()
 
+    def enable_saving_backtick_bookmark(self, boolean):
+        """
+        Adds or removes the ' from the list of nonpersitent bookmarks
+        """
+        if boolean:
+            if "'" in self.nonpersistent_bookmarks:
+                self.nonpersistent_bookmarks.remove("'")  # enable
+        else:
+            self.nonpersistent_bookmarks.add("'")  # disable
+
     def _load_dict(self):
         if self.path is None:
             return {}
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index 08a9c10c..6ffa5e2d 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -60,6 +60,7 @@ ALLOWED_SETTINGS = {
     'preview_images_method': str,
     'preview_max_size': int,
     'preview_script': (str, type(None)),
+    'save_backtick_bookmark': bool,
     'save_console_history': bool,
     'save_tabs_on_exit': bool,
     'scroll_offset': int,
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 76aa7876..a7f78f75 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -124,6 +124,8 @@ class FM(Actions,  # pylint: disable=too-many-instance-attributes
                 bookmarktype=Directory,
                 autosave=self.settings.autosave_bookmarks)
             self.bookmarks.load()
+            self.bookmarks.enable_saving_backtick_bookmark(
+                    self.settings.save_backtick_bookmark)
 
         self.ui.setup_curses()
         self.ui.initialize()
@@ -190,6 +192,10 @@ class FM(Actions,  # pylint: disable=too-many-instance-attributes
             'setopt.metadata_deep_search',
             lambda signal: setattr(signal.fm.metadata, 'deep_search', signal.value)
         )
+        self.settings.signal_bind(
+            'setopt.save_backtick_bookmark',
+            lambda signal: signal.fm.bookmarks.enable_saving_backtick_bookmark(signal.value)
+        )
 
     def destroy(self):
         debug = ranger.args.debug