Commit Diff


commit - d94d77bb038c1781eb565401b73dd89519341fb9
commit + 8225771f6b8018ee379e19205f42a157270c9fce
blob - 94896326f9b33d7724a6a358c58872902636a305
blob + f6f9a9bd6890469edf93808e2aa9c833ef8c549f
--- README.md
+++ README.md
@@ -41,7 +41,7 @@ Quick Start
   RETURN - open $SHELL on the current directory
    SPACE - open $PAGER with the selected file
        e - open $EDITOR with the selected file
-       o - open $ROVER_OPEN with the selected file
+       o - open $OPEN with the selected file
        / - start incremental search (RETURN to finish)
    f/d/s - toggle file/directory/hidden listing
      n/N - create new file/directory
@@ -78,6 +78,12 @@ via the appropriate environment variables. For example
  $ EDITOR=vi rover
  ```
 
+ Rover will first check for variables prefixed  with ROVER_. This can be used to
+change Rover behavior without interfering with the global environment:
+ ```
+ $ ROVER_EDITOR=vi rover
+ ```
+
  Please read rover(1) for more information.
 
 
blob - 1b97eb4c6bec57e414d29d05cb6ab372b3e5133d
blob + 321a61c90db0953abfb374ae6dcc83a4c97d0cec
--- rover.1
+++ rover.1
@@ -112,7 +112,7 @@ Open \fB$PAGER\fR with the selected file.
 Open \fB$EDITOR\fR with the selected file.
 .TP
 .B o
-Open \fB$ROVER_OPEN\fR with the selected file.
+Open \fB$OPEN\fR with the selected file.
 .TP
 .B /
 Start incremental search.
@@ -194,9 +194,13 @@ subprocess. This allows one to use the selection as pa
 by first invoking a shell from Rover (see the \fBCOMMANDS\fR section) and then
 typing something like \fBgrep abc "$RVSEL"\fR.
 .TP
-.B ROVER_OPEN
+.B OPEN
 This variable can be set to a command accepting a single argument: a filename.
 The command is supposed to open the given file with an appropriate program.
+.TP
+.B ROVER_SHELL, ROVER_PAGER, ROVER_EDITOR, ROVER_OPEN
+If any of these variables are set, they override \fBSHELL\fR, \fBPAGER\fR,
+\fBEDITOR\fR and \fBOPEN\fR, respectivelly.
 .SH CONFIGURATION
 .PP
 If you want to change Rover key bindings or colors, you can edit the
blob - 5e43e7ad2fb3fa8172ec10e30a38e5124f7e2a25
blob + 2665a989a6773868b1b28717267b7c1d3de3b380
--- rover.c
+++ rover.c
@@ -37,6 +37,12 @@ static char BUF1[BUFLEN];
 static char BUF2[BUFLEN];
 static char INPUT[BUFLEN];
 static wchar_t WBUF[BUFLEN];
+
+/* Paths to external programs. */
+static char *user_shell;
+static char *user_pager;
+static char *user_editor;
+static char *user_open;
 
 /* Listing view parameters. */
 #define HEIGHT      (LINES-4)
@@ -309,6 +315,20 @@ rover_get_wch(wint_t *wch)
     while ((ret = get_wch(wch)) == (wint_t) ERR)
         sync_signals();
     return ret;
+}
+
+/* Get user programs from the environment. */
+
+#define ROVER_ENV(dst, src) if ((dst = getenv("ROVER_" #src)) == NULL) \
+                                dst = getenv(#src);
+
+static void
+get_user_programs()
+{
+    ROVER_ENV(user_shell, SHELL)
+    ROVER_ENV(user_pager, PAGER)
+    ROVER_ENV(user_editor, EDITOR)
+    ROVER_ENV(user_open, OPEN)
 }
 
 /* Do a fork-exec to external program (e.g. $EDITOR). */
@@ -359,9 +379,8 @@ done:
 }
 
 static int
-open_with_env(const char *env, char *path)
+open_with_env(char *program, char *path)
 {
-    char *program = getenv(env);
     if (program) {
 #ifdef RV_SHELL
         strncpy(BUF1, program, BUFLEN - 1);
@@ -1036,6 +1055,7 @@ main(int argc, char *argv[])
             }
         }
     }
+    get_user_programs();
     init_term();
     rover.nfiles = 0;
     for (i = 0; i < 10; i++) {
@@ -1164,7 +1184,7 @@ main(int argc, char *argv[])
         } else if (!strcmp(key, RVK_REFRESH)) {
             reload();
         } else if (!strcmp(key, RVK_SHELL)) {
-            program = getenv("SHELL");
+            program = user_shell;
             if (program) {
 #ifdef RV_SHELL
                 spawn((char *[]) {RV_SHELL, "-c", program, NULL});
@@ -1175,15 +1195,15 @@ main(int argc, char *argv[])
             }
         } else if (!strcmp(key, RVK_VIEW)) {
             if (!rover.nfiles || S_ISDIR(EMODE(ESEL))) continue;
-            if (open_with_env("PAGER", ENAME(ESEL)))
+            if (open_with_env(user_pager, ENAME(ESEL)))
                 cd(0);
         } else if (!strcmp(key, RVK_EDIT)) {
             if (!rover.nfiles || S_ISDIR(EMODE(ESEL))) continue;
-            if (open_with_env("EDITOR", ENAME(ESEL)))
+            if (open_with_env(user_editor, ENAME(ESEL)))
                 cd(0);
         } else if (!strcmp(key, RVK_OPEN)) {
             if (!rover.nfiles || S_ISDIR(EMODE(ESEL))) continue;
-            if (open_with_env("ROVER_OPEN", ENAME(ESEL)))
+            if (open_with_env(user_open, ENAME(ESEL)))
                 cd(0);
         } else if (!strcmp(key, RVK_SEARCH)) {
             int oldsel, oldscroll, length;