diff --git a/docs/wmenu.1.scd b/docs/wmenu.1.scd index 4519e8b..8faaf49 100644 --- a/docs/wmenu.1.scd +++ b/docs/wmenu.1.scd @@ -39,6 +39,9 @@ $PATH and runs the result. wmenu will not directly display the keyboard input, but instead replace it with asterisks. +*-d* _path_ + wmenu will use path instead of $PATH. + *-v* prints version information to stdout, then exits. diff --git a/menu.c b/menu.c index 207d71c..2df4196 100644 --- a/menu.c +++ b/menu.c @@ -26,6 +26,7 @@ struct menu *menu_create(menu_callback callback) { struct menu *menu = calloc(1, sizeof(struct menu)); menu->strncmp = strncmp; + menu->path = NULL; menu->font = "monospace 10"; menu->normalbg = 0x222222ff; menu->normalfg = 0xbbbbbbff; @@ -86,10 +87,11 @@ static bool parse_color(const char *color, uint32_t *result) { void menu_getopts(struct menu *menu, int argc, char *argv[]) { const char *usage = "Usage: wmenu [-biPv] [-f font] [-l lines] [-o output] [-p prompt]\n" - "\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color]\n"; + "\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color]\n" + "\t[-d path]\n"; int opt; - while ((opt = getopt(argc, argv, "bhiPvf:l:o:p:N:n:M:m:S:s:")) != -1) { + while ((opt = getopt(argc, argv, "bhiPvf:l:o:p:N:n:M:m:S:s:d:")) != -1) { switch (opt) { case 'b': menu->bottom = true; @@ -145,6 +147,9 @@ void menu_getopts(struct menu *menu, int argc, char *argv[]) { fprintf(stderr, "Invalid selection foreground color: %s", optarg); } break; + case 'd': + menu->path = optarg; + break; default: fprintf(stderr, "%s", usage); exit(EXIT_FAILURE); diff --git a/menu.h b/menu.h index fdd9ad2..d34000f 100644 --- a/menu.h +++ b/menu.h @@ -37,6 +37,8 @@ struct menu { bool passwd; // The font used to display the menu char *font; + // Alternative path + const char *path; // The number of lines to list items vertically int lines; // The name of the output to display on diff --git a/wmenu-run.c b/wmenu-run.c index 1b7b8c1..5cb1d88 100644 --- a/wmenu-run.c +++ b/wmenu-run.c @@ -10,7 +10,7 @@ #include "xdg-activation-v1-client-protocol.h" static void read_items(struct menu *menu) { - char *path = strdup(getenv("PATH")); + char *path = menu->path ? strdup(menu->path) : strdup(getenv("PATH")); for (char *p = strtok(path, ":"); p != NULL; p = strtok(NULL, ":")) { DIR *dir = opendir(p); if (dir == NULL) {