aboutsummaryrefslogtreecommitdiffstats
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
parentfec819a1a7b33811148750760879b5ee3ab0a0e0 (diff)
downloadranger-0ea94c81a2dff42c28e2655e5ba7987dc78f55be.tar.gz
Add option 'save_backtick_bookmark', fixes #947
-rw-r--r--doc/ranger.16
-rw-r--r--doc/ranger.pod5
-rw-r--r--doc/rifle.12
-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
7 files changed, 37 insertions, 4 deletions
diff --git a/doc/ranger.1 b/doc/ranger.1
index 91f10a58..1e745fb6 100644
--- a/doc/ranger.1
+++ b/doc/ranger.1
@@ -129,7 +129,7 @@
.\" ========================================================================
.\"
.IX Title "RANGER 1"
-.TH RANGER 1 "ranger-1.9.0b5" "09/26/2017" "ranger manual"
+.TH RANGER 1 "ranger-1.9.0b5" "10/01/2017" "ranger manual"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
@@ -839,6 +839,10 @@ to disable this feature.
Which script should handle generating previews? If the file doesn't exist, or
use_preview_script is off, ranger will handle previews itself by just printing
the content.
+.IP "save_backtick_bookmark [bool]" 4
+.IX Item "save_backtick_bookmark [bool]"
+Save the \f(CW\*(C`\`\*(C'\fR bookmark to disk. This bookmark is used to switch to the last
+directory by typing \f(CW\*(C`\`\`\*(C'\fR.
.IP "save_console_history [bool]" 4
.IX Item "save_console_history [bool]"
Should the console history be saved on exit? If disabled, the console history
diff --git a/doc/ranger.pod b/doc/ranger.pod
index 2ec98d2b..f7053361 100644
--- a/doc/ranger.pod
+++ b/doc/ranger.pod
@@ -841,6 +841,11 @@ Which script should handle generating previews? If the file doesn't exist, or
use_preview_script is off, ranger will handle previews itself by just printing
the content.
+=item save_backtick_bookmark [bool]
+
+Save the C<`> bookmark to disk. This bookmark is used to switch to the last
+directory by typing C<``>.
+
=item save_console_history [bool]
Should the console history be saved on exit? If disabled, the console history
diff --git a/doc/rifle.1 b/doc/rifle.1
index c9ffbf5f..4d501df0 100644
--- a/doc/rifle.1
+++ b/doc/rifle.1
@@ -129,7 +129,7 @@
.\" ========================================================================
.\"
.IX Title "RIFLE 1"
-.TH RIFLE 1 "rifle-1.9.0b5" "09/26/2017" "rifle manual"
+.TH RIFLE 1 "rifle-1.9.0b5" "10/01/2017" "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 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