about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authornfnty <git@nfnty.se>2017-04-12 01:56:30 +0200
committernfnty <git@nfnty.se>2017-04-12 01:56:30 +0200
commit51e86c62d0e3e7caf5d839219796ae2043646515 (patch)
tree38b8d1ea74202b82a5d60b0a0dac3389404f043f
parentac27f17599eb06076494fdf8b82bdb195270c8bb (diff)
downloadranger-51e86c62d0e3e7caf5d839219796ae2043646515.tar.gz
config/rc.conf: Properly set `preview_script` by default
Multiple users have complained about having problems with the way
`scope.sh` sourcing is handled:
* When running in clean mode
* When wanting to run with the default config
* When having non-default `$XDG_CONFIG_HOME`

Lays groundwork for further default setting handling in the future.

Fixes #840
Fixes #849
Closes #853
-rw-r--r--examples/rc_emacs.conf4
-rw-r--r--ranger/config/rc.conf4
-rw-r--r--ranger/container/settings.py17
3 files changed, 19 insertions, 6 deletions
diff --git a/examples/rc_emacs.conf b/examples/rc_emacs.conf
index 5fd32ee2..d3707a12 100644
--- a/examples/rc_emacs.conf
+++ b/examples/rc_emacs.conf
@@ -34,10 +34,10 @@ set show_hidden false
 # With "multiple", ranger will ask only if you delete multiple files at once.
 set confirm_on_delete multiple
 
-# Which script is used to generate file previews?
+# Use non-default path for file preview script?
 # ranger ships with scope.sh, a script that calls external programs (see
 # README.md for dependencies) to preview images, archives, etc.
-set preview_script ~/.config/ranger/scope.sh
+#set preview_script ~/.config/ranger/scope.sh
 
 # Use the external preview script or display simple plain text or image previews?
 set use_preview_script true
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 38d1b47d..9af5a953 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -40,10 +40,10 @@ set show_hidden false
 # With "multiple", ranger will ask only if you delete multiple files at once.
 set confirm_on_delete multiple
 
-# Which script is used to generate file previews?
+# Use non-default path for file preview script?
 # ranger ships with scope.sh, a script that calls external programs (see
 # README.md for dependencies) to preview images, archives, etc.
-set preview_script ~/.config/ranger/scope.sh
+#set preview_script ~/.config/ranger/scope.sh
 
 # Use the external preview script or display simple plain text or image previews?
 set use_preview_script true
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index b58165ca..70e299c7 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -7,6 +7,7 @@ import re
 import os.path
 from inspect import isfunction
 
+import ranger
 from ranger.ext.signals import SignalDispatcher
 from ranger.core.shared import FileManagerAware
 from ranger.gui.colorscheme import _colorscheme_name_to_class
@@ -169,6 +170,19 @@ class Settings(SignalDispatcher, FileManagerAware):
         self.signal_emit('setopt', **kws)
         self.signal_emit('setopt.' + name, **kws)
 
+    def _get_default(self, name):
+        if name == 'preview_script':
+            if ranger.args.clean:
+                value = self.fm.relpath('data/scope.sh')
+            else:
+                value = self.fm.confpath('scope.sh')
+                if not os.path.exists(value):
+                    value = self.fm.relpath('data/scope.sh')
+        else:
+            value = DEFAULT_VALUES[self.types_of(name)[0]]
+
+        return value
+
     def get(self, name, path=None):
         assert name in ALLOWED_SETTINGS, "No such setting: {0}!".format(name)
         if path:
@@ -193,8 +207,7 @@ class Settings(SignalDispatcher, FileManagerAware):
                     return self._tagsettings[tag][name]
 
         if name not in self._settings:
-            type_ = self.types_of(name)[0]
-            value = DEFAULT_VALUES[type_]
+            value = self._get_default(name)
             self._raw_set(name, value)
             self.__setattr__(name, value)
         return self._settings[name]