{ 't', SEL_MTIME },
{ CONTROL('L'), SEL_REDRAW },
/* Run command */
- { '!', SEL_RUN, "sh" },
- { 'z', SEL_RUN, "top" },
+ { 'z', SEL_RUN, "top" },
+ { '!', SEL_RUN, "sh", "SHELL" },
/* Run command with argument */
- { 'e', SEL_RUNARG, "vi" },
+ { 'e', SEL_RUNARG, "vi", "EDITOR" },
+ { 'p', SEL_RUNARG, "less", "PAGER" },
};
int sym; /* Key pressed */
enum action act; /* Action */
char *run; /* Program to run */
+ char *env; /* Environment variable to run */
};
#include "config.h"
}
}
+char *
+xgetenv(char *name, char *fallback)
+{
+ if (name == NULL)
+ return fallback;
+ char *value = getenv(name);
+ if (value)
+ return value;
+ return fallback;
+}
+
char *
openwith(char *file)
{
}
/* Returns SEL_* if key is bound and 0 otherwise
- Also modifies the run pointer (used on SEL_{RUN,RUNARG}) */
+ Also modifies the run and env pointers (used on SEL_{RUN,RUNARG}) */
int
-nextsel(char **run)
+nextsel(char **run, char **env)
{
int c, i;
for (i = 0; i < LEN(bindings); i++)
if (c == bindings[i].sym) {
*run = bindings[i].run;
+ *env = bindings[i].env;
return bindings[i].act;
}
regex_t re;
char *newpath;
struct stat sb;
- char *name, *bin, *dir, *tmp, *run;
+ char *name, *bin, *dir, *tmp, *run, *env;
int nowtyping = 0;
oldpath = NULL;
if (nowtyping)
goto moretyping;
nochange:
- switch (nextsel(&run)) {
+ switch (nextsel(&run, &env)) {
case SEL_QUIT:
free(path);
free(fltr);
oldpath = makepath(path, dents[cur].name);
goto begin;
case SEL_RUN:
+ run = xgetenv(env, run);
exitcurses();
spawn(run, NULL, path);
initcurses();
break;
case SEL_RUNARG:
name = dents[cur].name;
+ run = xgetenv(env, run);
exitcurses();
spawn(run, name, path);
initcurses();