Skip to content
Myr

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

11 files+130 added−1 removed

modified:completions/fish/fuzzel.fish+2 added-1 removed
40 unmodified lines
41complete -c fuzzel -x -s C -l border-color -d "border color (002b36ff)"42complete -c fuzzel -l show-actions -d "include desktop actions (e.g. \"New Window\") in the list"43complete -c fuzzel -l no-fuzzy -d "disable fuzzy matching"44complete -c fuzzel -l filter-desktop -d "filter desktop entries based on XDG_CURRENT_DESKTOP"45complete -c fuzzel -x -l fuzzy-min-length -d "search strings shorter than this will not be fuzzy matched"45complete -c fuzzel -l list-executables-in-path -d "filter desktop entries based on XDG_CURRENT_DESKTOP"46complete -c fuzzel -x -l fuzzy-min-length -d "list executables present in the path environment variable"47complete -c fuzzel -x -l fuzzy-max-length-discrepancy -d "maximum allowed length difference between the search string and a fuzzy match (2)"48complete -c fuzzel -x -l fuzzy-max-distance -d "maximum allowed levenshtein distance between the search string and a fuzzy match (1)"49complete -c fuzzel -x -l line-height -d "override the line height from font metrics, in points or pixels"50complete -c fuzzel -x -l letter-spacing -d "additional letter spacing, in points or pixels"
10 unmodified lines
modified:completions/zsh/_fuzzel+1 added
32 unmodified lines
33 '(-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 lines
modified:doc/fuzzel.ini.5.scd+4 added
145 unmodified lines
146*terminal*147 terminal command to use when launching 'terminal' programs,148 e.g. \"xterm -e\". Default: _$TERMINAL -e_.149150*list-executables-in-path*151 Boolean. When enabled, the list will include executables152 from the PATH environment variable. Default: _no_.153154*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_ID
274 unmodified lines
modified:CHANGELOG.md+3 added
36 unmodified lines
37 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]).4344[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/284505152### Changed53
568 unmodified lines
modified:config.c+4 added
780 unmodified lines
781782 else if (strcmp(key, "icons-enabled") == 0)783 return value_to_bool(ctx, &conf->icons_enabled);784785 else if (strcmp(key, "list-executables-in-path") == 0)786 return value_to_bool(ctx, &conf->list_executables_in_path);787788 else if (strcmp(key, "fields") == 0) {789 _Static_assert(sizeof(conf->match_fields) == sizeof(int),790 "enum is not 32-bit");791
766 unmodified lines
1558 .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 };15641565 add_default_key_bindings(conf);1566
76 unmodified lines
modified:config.h+2 added
160 unmodified lines
161 struct pt_or_px letter_spacing;162163 enum zwlr_layer_shell_v1_layer layer;164 bool exit_on_kb_focus_loss;165166 bool list_executables_in_path;167};168169typedef tll(char *) config_override_t;170
6 unmodified lines
modified:fuzzel.ini+1 added
9 unmodified lines
10# 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=no1516# anchor=center17# lines=1518# width=30
76 unmodified lines
modified:main.c+13 added
34 unmodified lines
35#include "shm.h"36#include "version.h"37#include "wayland.h"38#include "xdg.h"39#include "path.h"4041#define max(x, y) ((x) > (y) ? (x) : (y))4243struct context {
244 unmodified lines
288 " --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 lines
426 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;433434 if (filter_desktop) {
13 unmodified lines
448 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 lines
554 #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 277559560 static const struct option longopts[] = {561 {"config", required_argument, 0, OPT_CONFIG},562 {"check-config", no_argument, 0, OPT_CHECK_CONFIG},
33 unmodified lines
596 {"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},601602 /* dmenu mode */603 {"dmenu", no_argument, 0, 'd'},604 {"dmenu0", no_argument, 0, OPT_DMENU_NULL},
485 unmodified lines
1090 }1091 cmdline_overrides.fuzzy_max_distance_set = true;1092 break;10931094 case OPT_LIST_EXECS_IN_PATH:1095 cmdline_overrides.conf.list_executables_in_path = true;1096 break;10971098 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 lines
1327 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;13331334 _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 lines
modified:meson.build+1 added
145 unmodified lines
146 '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 lines
added:path.c+94 added
1#include "path.h"2#include "application.h"3#include "tllist.h"45#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>1213#define LOG_MODULE "path"14#define LOG_ENABLE_DBG 015#include "log.h"16#include "xdg.h"17#include "char32.h"1819void20path_find_programs(struct application_list *applications)21{22 const char *_path = getenv("PATH");2324 if (_path == NULL)25 return ;2627 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;5051 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 };7980 tll_push_back(entries, app);81 }82 }83 closedir(d);84 }85 free(copy);8687 applications->v = reallocarray(88 applications->v, applications->count + tll_length(entries), sizeof(applications->v[0]));8990 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 once23#include "application.h"45void path_find_programs(struct application_list *applications);