mirror of
https://codeberg.org/adnano/wmenu.git
synced 2025-10-29 05:40:20 -04:00
Add possibility to use alternative path
This commit is contained in:
parent
fc69aa6e2b
commit
5fa012f9ad
4 changed files with 13 additions and 3 deletions
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
9
menu.c
9
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);
|
||||
|
|
|
|||
2
menu.h
2
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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue