Add --list-executables-in-path command line option
Before adoption: this commit came in with the history the project adopted, so no landing records it.
This option include executables from the PATH environement variable to be included in the list.
authored by tet · committed by tet · parent 7385fc6 · Browse files · 11 files·+130 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+130 added−1 removed
- other:+130 added−1 removed
Provenance
- Commit
c1fdcb7- Tree
b375035- Author
tet <gmorer@pm.me>- Committer
tet <gmorer@pm.me>- Parent
7385fc6
11 files changed+130 added−1 removed
modified:completions/fish/fuzzel.fish+2 added-1 removed
40 unmodified lines41 complete -c fuzzel -x -s C -l border-color -d "border color (002b36ff)"42 complete -c fuzzel -l show-actions -d "include desktop actions (e.g. \"New Window\") in the list"43 complete -c fuzzel -l no-fuzzy -d "disable fuzzy matching"44 complete -c fuzzel -l filter-desktop -d "filter desktop entries based on XDG_CURRENT_DESKTOP"45-complete -c fuzzel -x -l fuzzy-min-length -d "search strings shorter than this will not be fuzzy matched"45+complete -c fuzzel -l list-executables-in-path -d "filter desktop entries based on XDG_CURRENT_DESKTOP"46+complete -c fuzzel -x -l fuzzy-min-length -d "list executables present in the path environment variable"47 complete -c fuzzel -x -l fuzzy-max-length-discrepancy -d "maximum allowed length difference between the search string and a fuzzy match (2)"48 complete -c fuzzel -x -l fuzzy-max-distance -d "maximum allowed levenshtein distance between the search string and a fuzzy match (1)"49 complete -c fuzzel -x -l line-height -d "override the line height from font metrics, in points or pixels"50 complete -c fuzzel -x -l letter-spacing -d "additional letter spacing, in points or pixels"10 unmodified linesmodified:completions/zsh/_fuzzel+1 added
32 unmodified lines33 '(-C --border-color)'{-C,--border-color}'[border color (002b36ff)]:border-color:()' \34 '--show-actions[include desktop actions (e.g "New Window") in the list]' \35 '--no-fuzzy[disable fuzzy matching]' \36 '--filter-desktop=-[filter desktop entries based on XDG_CURRENT_DESKTOP]: :(no)' \37+ '--list-executables-in-path[list executables present in the PATH environment variable]'\38 '--fuzzy-min-length[search strings shorter than this will not be fuzzy matched (3)]:()' \39 '--fuzzy-max-length-discrepancy[maximum allowed length difference between the search string and a fuzzy match (2)]:()' \40 '--fuzzy-max-distance[maximum allowed levenshtein distance between the search string and a fuzzy match (1)]:()' \41 '--line-height[override line height from font metrics, in points or pixels]:()' \29 unmodified linesmodified:doc/fuzzel.ini.5.scd+4 added
145 unmodified lines146 *terminal*147 terminal command to use when launching 'terminal' programs,148 e.g. \"xterm -e\". Default: _$TERMINAL -e_.149 150+*list-executables-in-path*151+ Boolean. When enabled, the list will include executables152+ from the PATH environment variable. Default: _no_.153+154 *launch-prefix*155 Prefix to add before argv of executed program.156 If set, fuzzel will pass the Desktop File ID of the chosen application157 (see the Desktop Entry specification) in the FUZZEL_DESKTOP_FILE_ID274 unmodified linesmodified:CHANGELOG.md+3 added
36 unmodified lines37 of whether it matches anything in the list or not ([#252][252]).38 * `--select=STRING` command line option. Selects the first entry that39 matches the given string ([#237][237]).40 * `include=<path>` option to `fuzzel.ini` ([#205][205]).41+* New option `--list-executables-in-path` add executables presents in42+ the $PATH variable to the list ([#284][284]).43 44 [130]: https://codeberg.org/dnkl/fuzzel/issues/13045 [264]: https://codeberg.org/dnkl/fuzzel/issues/26446 [252]: https://codeberg.org/dnkl/fuzzel/issues/25247 [237]: https://codeberg.org/dnkl/fuzzel/issues/23748 [205]: https://codeberg.org/dnkl/fuzzel/issues/20549+[284]: https://codeberg.org/dnkl/fuzzel/pulls/28450 51 52 ### Changed53 568 unmodified linesmodified:config.c+4 added
780 unmodified lines781 782 else if (strcmp(key, "icons-enabled") == 0)783 return value_to_bool(ctx, &conf->icons_enabled);784 785+ else if (strcmp(key, "list-executables-in-path") == 0)786+ return value_to_bool(ctx, &conf->list_executables_in_path);787+788 else if (strcmp(key, "fields") == 0) {789 _Static_assert(sizeof(conf->match_fields) == sizeof(int),790 "enum is not 32-bit");791 766 unmodified lines1558 .line_height = {-1, 0.0},1559 .letter_spacing = {0},1560 .layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP,1561 .exit_on_kb_focus_loss = true,1562+ .list_executables_in_path = false,1563 };1564 1565 add_default_key_bindings(conf);1566 76 unmodified linesmodified:config.h+2 added
160 unmodified lines161 struct pt_or_px letter_spacing;162 163 enum zwlr_layer_shell_v1_layer layer;164 bool exit_on_kb_focus_loss;165+166+ bool list_executables_in_path;167 };168 169 typedef tll(char *) config_override_t;170 6 unmodified linesmodified:fuzzel.ini+1 added
9 unmodified lines10 # fuzzy=yes11 # show-actions=no12 # terminal=$TERMINAL -e # Note: you cannot actually use environment variables here13 # launch-prefix=<not set>14+# list-executables-in-path=no15 16 # anchor=center17 # lines=1518 # width=3076 unmodified linesmodified:main.c+13 added
34 unmodified lines35 #include "shm.h"36 #include "version.h"37 #include "wayland.h"38 #include "xdg.h"39+#include "path.h"40 41 #define max(x, y) ((x) > (y) ? (x) : (y))42 43 struct context {244 unmodified lines288 " --dmenu0 like --dmenu, but input is NUL separated\n"289 " instead of newline separated\n"290 " --index print selected entry's index instead of of the \n"291 " entry's text (dmenu mode only)\n"292+ " --list-executables-in-path include executables from PATH in the list\n"293 " -R,--no-run-if-empty exit immediately without showing UI if stdin\n"294 " is empty (dmenu mode only)\n"295 " --log-level={info|warning|error|none}\n"296 " log level (warning)\n"129 unmodified lines426 bool dmenu_enabled = conf->dmenu.enabled;427 bool icons_enabled = conf->icons_enabled;428 char dmenu_delim = conf->dmenu.delim;429 bool filter_desktop = conf->filter_desktop;430+ bool list_exec_in_path = conf->list_executables_in_path;431 char_list_t desktops = tll_init();432 char *saveptr = NULL;433 434 if (filter_desktop) {13 unmodified lines448 if (dmenu_enabled)449 dmenu_load_entries(apps, dmenu_delim, ctx->dmenu_abort_fd);450 else {451 xdg_find_programs(terminal, actions_enabled, filter_desktop, &desktops, apps);452+ if (list_exec_in_path)453+ path_find_programs(apps);454 read_cache(apps);455 }456 tll_free_and_free(desktops, free);457 96 unmodified lines554 #define OPT_DMENU_NULL 273555 #define OPT_FILTER_DESKTOP 274556 #define OPT_CHECK_CONFIG 275557 #define OPT_SELECT 276558+ #define OPT_LIST_EXECS_IN_PATH 277559 560 static const struct option longopts[] = {561 {"config", required_argument, 0, OPT_CONFIG},562 {"check-config", no_argument, 0, OPT_CHECK_CONFIG},33 unmodified lines596 {"letter-spacing", required_argument, 0, OPT_LETTER_SPACING},597 {"launch-prefix", required_argument, 0, OPT_LAUNCH_PREFIX},598 {"layer", required_argument, 0, OPT_LAYER},599 {"no-exit-on-keyboard-focus-loss", no_argument, 0, OPT_NO_EXIT_ON_KB_LOSS},600+ {"list-executables-in-path", no_argument, 0, OPT_LIST_EXECS_IN_PATH},601 602 /* dmenu mode */603 {"dmenu", no_argument, 0, 'd'},604 {"dmenu0", no_argument, 0, OPT_DMENU_NULL},485 unmodified lines1090 }1091 cmdline_overrides.fuzzy_max_distance_set = true;1092 break;1093 1094+ case OPT_LIST_EXECS_IN_PATH:1095+ cmdline_overrides.conf.list_executables_in_path = true;1096+ break;1097+1098 case 'H': { /* line-height */1099 if (!pt_or_px_from_string(optarg, &cmdline_overrides.conf.line_height))1100 return EXIT_FAILURE;1101 cmdline_overrides.line_height_set = true;225 unmodified lines1327 if (cmdline_overrides.dmenu_mode_set)1328 conf.dmenu.mode = cmdline_overrides.conf.dmenu.mode;1329 if (cmdline_overrides.dmenu_exit_immediately_if_empty_set)1330 conf.dmenu.exit_immediately_if_empty = cmdline_overrides.conf.dmenu.exit_immediately_if_empty;1331+ if (cmdline_overrides.conf.list_executables_in_path)1332+ conf.list_executables_in_path = cmdline_overrides.conf.list_executables_in_path;1333 1334 _Static_assert((int)LOG_CLASS_ERROR == (int)FCFT_LOG_CLASS_ERROR,1335 "fcft log level enum offset");1336 _Static_assert((int)LOG_COLORIZE_ALWAYS == (int)FCFT_LOG_COLORIZE_ALWAYS,208 unmodified linesmodified:meson.build+1 added
145 unmodified lines146 'key-binding.c', 'key-binding.h',147 'log.c', 'log.h',148 'main.c',149 'match.c', 'match.h',150+ 'path.c', 'path.h',151 'png.c', 'png-fuzzel.h',152 'prompt.c', 'prompt.h',153 'render.c', 'render.h',154 'shm.c', 'shm.h',38 unmodified linesadded:path.c+94 added
1+#include "path.h"2+#include "application.h"3+#include "tllist.h"4+5+#include <string.h>6+#include <fcntl.h>7+#include <sys/types.h>8+#include <sys/stat.h>9+#include <dirent.h>10+#include <stdlib.h>11+#include <stdio.h>12+13+#define LOG_MODULE "path"14+#define LOG_ENABLE_DBG 015+#include "log.h"16+#include "xdg.h"17+#include "char32.h"18+19+void20+path_find_programs(struct application_list *applications)21+{22+ const char *_path = getenv("PATH");23+24+ if (_path == NULL)25+ return ;26+27+ char *copy = strdup(_path);28+ char *ctx = NULL;29+ tll(struct application) entries = tll_init();30+ 31+ for (const char *tok = strtok_r(copy, ":", &ctx);32+ tok != NULL;33+ tok = strtok_r(NULL, ":", &ctx))34+ {35+ DIR *d = opendir(tok);36+ if (d == NULL) {37+ LOG_WARN("failed to open %s from PATH", tok);38+ continue;39+ }40+ int fd = dirfd(d);41+ if (fd == -1) {42+ LOG_WARN("failed to open %s's fd from PATH", tok);43+ closedir(d);44+ continue;45+ }46+ const size_t path_size = strlen(tok);47+ for (const struct dirent *e = readdir(d); e != NULL; e = readdir(d)) {48+ if (strcmp(e->d_name, ".") == 0 || strcmp(e->d_name, "..") == 0)49+ continue;50+51+ struct stat st;52+ if (fstatat(fd, e->d_name, &st, 0) == -1) {53+ LOG_WARN("%s: failed to stat", e->d_name);54+ continue;55+ }56+ if (S_ISREG(st.st_mode) && st.st_mode & S_IXUSR) {57+ char32_t *wtitle = ambstoc32(e->d_name);58+ if (wtitle == NULL)59+ continue;60+ bool already_exist = false;61+ tll_foreach(entries, it) {62+ if (c32cmp(wtitle, it->item.title) == 0) {63+ already_exist = true;64+ break;65+ }66+ };67+ if (already_exist) {68+ free(wtitle);69+ continue;70+ }71+ size_t exec_size = path_size + 1 + strlen(e->d_name) + 1;72+ char *exec = malloc(exec_size);73+ snprintf(exec, exec_size, "%s/%s", tok, e->d_name);74+ struct application app = {75+ .title = wtitle,76+ .exec = exec,77+ .visible = true,78+ };79+80+ tll_push_back(entries, app);81+ }82+ }83+ closedir(d);84+ }85+ free(copy);86+87+ applications->v = reallocarray(88+ applications->v, applications->count + tll_length(entries), sizeof(applications->v[0]));89+90+ tll_foreach(entries, it) {91+ applications->v[applications->count++] = it->item;92+ tll_remove(entries, it);93+ }94+}added:path.h+5 added
1+#pragma once2+3+#include "application.h"4+5+void path_find_programs(struct application_list *applications);