about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2013-02-22 02:17:17 +0100
committerhut <hut@lavabit.com>2013-02-22 02:25:57 +0100
commit8bcfc1988283736d2cd5405789f04db8ccf151c3 (patch)
tree961892586e90ed4c37b39361a28ba4ff27d6e5b7
parent4537b1ab36f60baf4915f8378e26c13f9fa0d688 (diff)
downloadranger-8bcfc1988283736d2cd5405789f04db8ccf151c3.tar.gz
ext.rifle: better searching for configuration file
-rwxr-xr-xranger/ext/rifle.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py
index e5cf17b4..dff87b5a 100755
--- a/ranger/ext/rifle.py
+++ b/ranger/ext/rifle.py
@@ -373,9 +373,19 @@ def main():
         conf_path = os.environ['XDG_CONFIG_HOME'] + '/ranger/rifle.conf'
     else:
         conf_path = os.path.expanduser('~/.config/ranger/rifle.conf')
+    default_conf_path = conf_path
     if not os.path.isfile(conf_path):
         conf_path = os.path.normpath(os.path.join(os.path.dirname(__file__),
             '../config/rifle.conf'))
+    if not os.path.isfile(conf_path):
+        try:
+            # if ranger is installed, get the configuration from ranger
+            import ranger
+        except ImportError:
+            pass
+        else:
+            conf_path = os.path.join(ranger.__path__[0], "config", "rifle.conf")
+
 
     # Evaluate arguments
     from optparse import OptionParser
@@ -396,6 +406,11 @@ def main():
         parser.print_help()
         raise SystemExit(1)
 
+    if not os.path.isfile(conf_path):
+        sys.stderr.write("Could not find a configuration file.\n"
+                "Please create one at %s.\n" % default_conf_path)
+        raise SystemExit(1)
+
     if options.p.isdigit():
         number = int(options.p)
         label = None