summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--doc/rifle.110
-rw-r--r--doc/rifle.pod11
-rwxr-xr-xranger/ext/rifle.py34
3 files changed, 42 insertions, 13 deletions
diff --git a/doc/rifle.1 b/doc/rifle.1
index ba985281..07875bc2 100644
--- a/doc/rifle.1
+++ b/doc/rifle.1
@@ -139,7 +139,7 @@ rifle \- ranger's file opener
 .SH "SYNOPSIS"
 .IX Header "SYNOPSIS"
 \&\fBrifle\fR [\fB\-\-help\fR] [\fB\-f\fR \fI\s-1FLAGS\s0\fR] [\fB\-l\fR] [\fB\-p\fR \fI\s-1KEYWORD\s0\fR]
-[\fB\-w\fR \fI\s-1PROGRAM\s0\fR] \fIfiles\fR
+[\fB\-w\fR \fI\s-1PROGRAM\s0\fR] [\fB\-c\fR \fI\s-1CONFIG_FILE\s0\fR] \fIfiles\fR
 .SH "DESCRIPTION"
 .IX Header "DESCRIPTION"
 rifle is a powerful file executor that allows for complex file type checking,
@@ -170,14 +170,18 @@ Pick a method to open the files.
 .IP "\fB\-w\fR \fI\s-1PROGRAM\s0\fR" 14
 .IX Item "-w PROGRAM"
 Open the files with the program \fI\s-1PROGRAM\s0\fR
+.IP "\fB\-c\fR \fI\s-1CONFIG_FILE\s0\fR" 14
+.IX Item "-c CONFIG_FILE"
+Read configuration from \fI\s-1CONFIG_FILE\s0\fR, instead of the default.
 .IP "\fB\-h\fR, \fB\-\-help\fR" 14
 .IX Item "-h, --help"
 Print a list of options and exit.
 .SH "FILES"
 .IX Header "FILES"
 rifle shares configuration files with ranger, though ranger is not required in
-order to use rifle.  The configuration file \fIrifle.conf\fR is expected to be at
-\&\fI~/.config/ranger/rifle.conf\fR.
+order to use rifle. The default configuration file \fIrifle.conf\fR is expected
+to be at \fI~/.config/ranger/rifle.conf\fR. However, this can be overridden with
+the \fB\-c\fR option.
 .PP
 This file specifies patterns for determining the commands to open files with.
 The syntax is described in the comments of the default \fIrifle.conf\fR that ships
diff --git a/doc/rifle.pod b/doc/rifle.pod
index ea04c5ee..7241f6b5 100644
--- a/doc/rifle.pod
+++ b/doc/rifle.pod
@@ -8,7 +8,7 @@ rifle - ranger's file opener
 =head1 SYNOPSIS
 
 B<rifle> [B<--help>] [B<-f> I<FLAGS>] [B<-l>] [B<-p> I<KEYWORD>]
-[B<-w> I<PROGRAM>] I<files>
+[B<-w> I<PROGRAM>] [B<-c> I<CONFIG_FILE>] I<files>
 
 
 
@@ -53,6 +53,10 @@ I<KEYWORD> is either the ID number listed by C<rifle -l> or a string that matche
 
 Open the files with the program I<PROGRAM>
 
+=item B<-c> I<CONFIG_FILE>
+
+Read configuration from I<CONFIG_FILE>, instead of the default.
+
 =item B<-h>, B<--help>
 
 Print a list of options and exit.
@@ -65,8 +69,9 @@ Print a list of options and exit.
 =head1 FILES
 
 rifle shares configuration files with ranger, though ranger is not required in
-order to use rifle.  The configuration file F<rifle.conf> is expected to be at
-F<~/.config/ranger/rifle.conf>.
+order to use rifle. The default configuration file F<rifle.conf> is expected
+to be at F<~/.config/ranger/rifle.conf>. However, this can be overridden with
+the B<-c> option.
 
 This file specifies patterns for determining the commands to open files with.
 The syntax is described in the comments of the default F<rifle.conf> that ships
diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py
index 89ee7fa2..0bba937d 100755
--- a/ranger/ext/rifle.py
+++ b/ranger/ext/rifle.py
@@ -380,9 +380,7 @@ class Rifle(object):  # pylint: disable=too-many-instance-attributes
                 self.hook_after_executing(command, self._mimetype, self._app_flags)
 
 
-def main():  # pylint: disable=too-many-locals
-    """The main function which is run when you start this program direectly."""
-
+def find_conf_path():
     # Find configuration file path
     if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']:
         conf_path = os.environ['XDG_CONFIG_HOME'] + '/ranger/rifle.conf'
@@ -401,6 +399,17 @@ def main():  # pylint: disable=too-many-locals
         else:
             conf_path = os.path.join(ranger.__path__[0], "config", "rifle.conf")
 
+    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)
+        return None
+
+    return conf_path
+
+
+def main():  # pylint: disable=too-many-locals
+    """The main function which is run when you start this program direectly."""
+
     # Evaluate arguments
     from optparse import OptionParser  # pylint: disable=deprecated-module
     parser = OptionParser(usage="%prog [-fhlpw] [files]", version=__version__)
@@ -415,15 +424,26 @@ def main():  # pylint: disable=too-many-locals
                       "the configuration file")
     parser.add_option('-w', type='string', default=None, metavar="PROGRAM",
                       help="open the files with PROGRAM")
+    parser.add_option('-c', type='string', default=None, metavar="CONFIG_FILE",
+                      help="read config from specified file instead of default")
     options, positional = parser.parse_args()
     if not positional:
         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.c is None:
+        conf_path = find_conf_path()
+        if not conf_path:
+            raise SystemExit(1)
+    else:
+        try:
+            conf_path = os.path.abspath(options.c)
+        except OSError as ex:
+            sys.stderr.write("Unable to access specified configuration file: {0}\n".format(ex))
+            raise SystemExit(1)
+        if not os.path.isfile(conf_path):
+            sys.stderr.write("Specified configuration file not found: {0}\n".format(conf_path))
+            raise SystemExit(1)
 
     if options.p.isdigit():
         number = int(options.p)