Skip to content
Myr

dmenu: add --only-match

Before adoption: this commit came in with the history the project adopted, so no landing records it.

By default, fuzzel allows the user to execute/select text that isn't a listed entry. In application mode, this allows the user to type custom command lines. In dmenu mode, it allows the user to input/select text not in the list. Sometimes it's desirable to prevent this in dmenu mode, forcing the user to either select one of the available entries, or abort. This is what --only-match does. Closes #651

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 33116fd · Browse files · 7 files+44 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+44 added−4 removed

  • other:+44 added−4 removed

7 files+44 added−4 removed

modified:completions/fish/fuzzel.fish+1 added
82 unmodified lines
83complete -c fuzzel -x -l with-nth -d "display the N:th column (tab separated by default) of each input line (dmenu only)"84complete -c fuzzel -x -l accept-nth -d "output the N:th column (tab separated by default) of each input line (dmenu only)"85complete -c fuzzel -x -l match-nth -d "match against the N:th column (tab separated by default) of each input line (dmenu only)"86complete -c fuzzel -x -l nth-delimiter -d "field delimiter for --with-nth and --accept-nth"87complete -c fuzzel -x -l only-match -d "do not allow custom entries, only return a selected item"88complete -c fuzzel -s R -l no-run-if-empty -d "exit immediately without showing the UI if stdin is empty (dmenu mode only)"89complete -c fuzzel -x -s d -l log-level -a "info warning error none" -d "log-level (warning)"90complete -c fuzzel -x -s l -l log-colorize -a "always never auto" -d "enable or disable colorization of log output on stderr"91complete -c fuzzel -s S -l log-no-syslog -d "disable syslog logging"
4 unmodified lines
modified:completions/zsh/_fuzzel+1 added
73 unmodified lines
74 '--with-nth[display the N:th column (tab separated by default) of each input line (dmenu mode only)]:with-nth:()' \75 '--accept-nth[output the N:th column (tab separated by default) of each input line (dmenu mode only)]:accept-nth:()' \76 '--match-nth[match against the N:th column (tab separated by default) of each input line (dmenu only)]:match-nth:()' \77 '--nth-delimiter[field delimiter for --with-nth and --accept-nth]:nth-delim:()' \78 '--only-match[do not allow custom entries, only return a selected item]:only-match:()' \79 '(-R --no-run-if-empty)'{-R,--no-run-if-empty}'[exit immediately without showing the UI if stdin is empty (dmenu mode only)]' \80 '--log-level[log level (warning)]:loglevel:(info warning error none)' \81 '--log-colorize[enable or disable colorization of log output on stderr]:logcolor:(never always auto)' \82 '--log-no-syslog[disable syslog logging]' \
23 unmodified lines
modified:doc/fuzzel.1.scd+8 added
550 unmodified lines
551 be a single ASCII character.552553 Default: _\\t_ (tab)554555*--only-match*556 Do not allow custom entries, only return a selected item. In this557 mode, fuzzel always returns an entry. It will not return if no558 matching entry is selected.559560 The exception to this is the *execute-input* key binding, which561 always executes/selects the input text.562563*-R*,*--no-run-if-empty*564 Exit immediately, without showing the UI, if stdin is565 empty. dmenu mode only.566
91 unmodified lines
modified:CHANGELOG.md+3 added
39 unmodified lines
40 be removed in a future release ([#650][650]).41* `--match-nth=N` command line option, allowing dmenu entries to be42 matched against text other than what is being displayed43 ([#589][589]).44* `--only-match` command line option, preventing the user from45 executing "custom" input in dmenu mode ([#651][651]).4647[650]: https://codeberg.org/dnkl/fuzzel/issues/65048[589]: https://codeberg.org/dnkl/fuzzel/issues/58949[651]: https://codeberg.org/dnkl/fuzzel/issues/6515051### Changed52### Deprecated53### Removed
1063 unmodified lines
modified:config.h+1 added
162 unmodified lines
163 struct {164 bool enabled;165 enum dmenu_mode mode;166 bool exit_immediately_if_empty;167 bool only_match;168 char delim;169 char nth_delim;170 char *with_nth_format;171 char *accept_nth_format;
68 unmodified lines
modified:main.c+12 added
444 unmodified lines
445 " default) of each input line, instead of what is\n"446 " being displayed (dmenu only)\n"447 " --nth-delimiter=CHARACTER field (column) character, for --with-nth and\n"448 " --accept-nth\n"449 " --only-match do not allow custom entries, only return a\n"450 " selected item\n"451 " -R,--no-run-if-empty exit immediately without showing UI if stdin\n"452 " is empty (dmenu mode only)\n"453 " --log-level={info|warning|error|none}\n"454 " log level (warning)\n"
403 unmodified lines
858 #define OPT_SELECTION_RADIUS 306859 #define OPT_NO_MOUSE 307860 #define OPT_DMENU_NTH_DELIM 308861 #define OPT_DMENU_MATCH_NTH 309862 #define OPT_DMENU_ONLY_MATCH 310863864 static const struct option longopts[] = {865 {"config", required_argument, 0, OPT_CONFIG},866 {"check-config", no_argument, 0, OPT_CHECK_CONFIG},
72 unmodified lines
939 {"nth-delimiter", required_argument, 0, OPT_DMENU_NTH_DELIM},940 {"with-nth", required_argument, 0, OPT_DMENU_WITH_NTH},941 {"accept-nth", required_argument, 0, OPT_DMENU_ACCEPT_NTH},942 {"match-nth", required_argument, 0, OPT_DMENU_MATCH_NTH},943 {"only-match", no_argument, 0, OPT_DMENU_ONLY_MATCH},944945 /* Misc */946 {"log-level", required_argument, 0, OPT_LOG_LEVEL},947 {"log-colorize", optional_argument, 0, OPT_LOG_COLORIZE},
59 unmodified lines
1007 bool dmenu_nth_delim_set:1;1008 bool dmenu_with_nth_set:1;1009 bool dmenu_accept_nth_set:1;1010 bool dmenu_match_nth_set:1;1011 bool dmenu_only_match_set:1;1012 bool layer_set:1;1013 bool keyboard_focus_set:1;1014 bool no_exit_on_keyboard_focus_loss_set:1;1015 bool render_workers_set:1;
782 unmodified lines
1798 cmdline_overrides.dmenu_match_nth_set = true;1799 break;1800 }18011802 case OPT_DMENU_ONLY_MATCH:1803 cmdline_overrides.conf.dmenu.only_match = true;1804 cmdline_overrides.dmenu_only_match_set = true;1805 break;18061807 case OPT_LOG_LEVEL: {1808 int lvl = log_level_from_string(optarg);1809 if (lvl < 0) {1810 fprintf(
317 unmodified lines
2128 if (cmdline_overrides.dmenu_match_nth_set) {2129 free(conf.dmenu.match_nth_format);2130 conf.dmenu.match_nth_format = cmdline_overrides.conf.dmenu.match_nth_format;2131 }2132 if (cmdline_overrides.dmenu_only_match_set)2133 conf.dmenu.only_match = cmdline_overrides.conf.dmenu.only_match;2134 if (cmdline_overrides.conf.list_executables_in_path)2135 conf.list_executables_in_path = cmdline_overrides.conf.list_executables_in_path;2136 if (cmdline_overrides.render_workers_set)2137 conf.render_worker_count = cmdline_overrides.conf.render_worker_count;
255 unmodified lines
modified:wayland.c+18 added-4 removed
799 unmodified lines
800 case BIND_ACTION_PRIMARY_PASTE:801 paste_from_primary(seat);802 return true;803804 case BIND_ACTION_MATCHES_EXECUTE:805 /* Ignore execute action if prompt empty and no matches */806 if (prompt_text(wayl->prompt)[0] != '\0' || matches_get_total_count(wayl->matches) != 0)807 execute_selected(seat, false, -1);804 case BIND_ACTION_MATCHES_EXECUTE: {805 const size_t match_count = matches_get_total_count(wayl->matches);806807 if (prompt_text(wayl->prompt)[0] == '\0' && match_count == 0) {808 /* Empty prompt, and no matches -> do nothing */809 return true;810 }811812 const bool dmenu_enabled = wayl->conf->dmenu.enabled;813 const bool only_match = wayl->conf->dmenu.only_match;814815 if (dmenu_enabled && only_match && match_count == 0) {816 /* --only-match, and no matches -> do nothing */817 return true;818 }819820 execute_selected(seat, false, -1);821 return true;822 }823824 case BIND_ACTION_MATCHES_EXECUTE_OR_NEXT:825 if (matches_get_total_count(wayl->matches) == 1)826 execute_selected(seat, false, -1);
2346 unmodified lines