Add --with-nth=N command line option
Before adoption: this commit came in with the history the project adopted, so no landing records it.
This option (dmenu mode only) causes fuzzel to display the N:th column of each input string, while still printing the full string to stdout when "executed". Only supported column separator is tabs. Example: printf "1\tFirst\n2\tSecond" | fuzzel --with-nth=2 Displays the entries "First" and "Second". When selected, either "1\tFirst" or "2\tSecond" is printed on stdout. Closes #438
authored by Daniel Eklöf · committed by Daniel Eklöf · parent 71cbf97 · Browse files · 8 files·+81 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+81 added−3 removed
- other:+81 added−3 removed
Provenance
- Commit
36471ff- Tree
c7ccfaa- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
71cbf97
8 files changed+81 added−3 removed
modified:completions/fish/fuzzel.fish+1 added
68 unmodified lines69 complete -c fuzzel -x -l delayed-filter-limit -d "switch to delayed refiltering when there are more matches than this"70 complete -c fuzzel -s d -l dmenu -d "dmenu compatibility mode; entries are read from stdin, newline separated"71 complete -c fuzzel -l dmenu0 -d "dmenu compatibility mode; entries are read from stdin, NUL separated"72 complete -c fuzzel -l index -d "print selected entry's index instead of its text (dmenu mode only)"73+complete -c fuzzel -x -l with-nth -d "display the N:th column (tab separated) of each input line (dmenu only)"74 complete -c fuzzel -s R -l no-run-if-empty -d "exit immediately without showing the UI if stdin is empty (dmenu mode only)"75 complete -c fuzzel -x -s d -l log-level -a "info warning error none" -d "log-level (warning)"76 complete -c fuzzel -x -s l -l log-colorize -a "always never auto" -d "enable or disable colorization of log output on stderr"77 complete -c fuzzel -s S -l log-no-syslog -d "disable syslog logging"2 unmodified linesmodified:completions/zsh/_fuzzel+2 added-1 removed
59 unmodified lines60 '--delayed-filter-ms[time in milliseconds to delay refiltering when there are lots of matches]:delayed-filter-ms:()' \61 '--delayed-filter-limit[switch to delayed refiltering when there are more matches than this]:delayed-filter-limit:()' \62 '(-d --dmenu)'{-d,--dmenu}'[dmenu compatibility mode; entries are read from stdin, newline separated]' \63 '--dmenu0[dmenu compatibility mode; entries are read from stdin, NUL separated]' \64- "--index[print selected entry's index instead of its text (dmenu mode only)]" \64+ '--index[print selected entry's index instead of its text (dmenu mode only)]' \65+ '--with-nth[display the N:th column (tab separated) of each input line (dmenu mode only)]:with-nth:()' \66 '(-R --no-run-if-empty)'{-R,--no-run-if-empty}'[exit immediately without showing the UI if stdin is empty (dmenu mode only)]' \67 '--log-level[log level (warning)]:loglevel:(info warning error none)' \68 '--log-colorize[enable or disable colorization of log output on stderr]:logcolor:(never always auto)' \69 '--log-no-syslog[disable syslog logging]'20 unmodified linesmodified:doc/fuzzel.1.scd+19 added-2 removed
369 unmodified lines370 371 *--index*372 Print selected entry's index instead of its text.373 Index values start with zero for the first entry.374- **dmenu** mode only.374+ dmenu mode only.375 376+*--with-nth*=_N_377+ Display the N:th column (tab separated) of each input line. When378+ selected, the full input line is printed on stdout. dmenu mode379+ only.380+ 381+ Example:382+ ```383+ printf "1\tFirst\n2\tSecond" | fuzzel --with-nth=2384+ ```385+ 386+ This will display the entries *First* and *Second*. When one of387+ them has selected, the full input line (tabs included) are printed388+ on stdout.389+ 390+ Setting it to *0* is the same as not specifying *--with-nth* at391+ all.392+393 *-R*,*--no-run-if-empty*394 Exit immediately, without showing the UI, if stdin is378- empty. **dmenu** mode only.395+ empty. dmenu mode only.396 397 *--log-level*={*info*,*warning*,*error*,*none*}398 Log level, used both for log output on stderr as well as399 syslog. Default: _warning_.68 unmodified linesmodified:CHANGELOG.md+1 added
30 unmodified lines31 ## Unreleased32 ### Added33 34 * Nanosvg updated to ea6a6aca009422bba0dbad4c80df6e6ba0c8218335+* `--with-nth=N` command line option ([#438][438]).36 37 38 ### Changed39 871 unmodified linesmodified:config.c+1 added
1608 unmodified lines1609 .enabled = false,1610 .mode = DMENU_MODE_TEXT,1611 .exit_immediately_if_empty = false,1612 .delim = '\n',1613+ .render_column = 0,1614 },1615 .anchor = ANCHOR_CENTER,1616 .margin = {1617 .x = 0,114 unmodified linesmodified:config.h+1 added
148 unmodified lines149 bool enabled;150 enum dmenu_mode mode;151 bool exit_immediately_if_empty;152 char delim;153+ unsigned int render_column;154 } dmenu;155 156 enum anchors anchor;157 54 unmodified linesmodified:main.c+18 added
403 unmodified lines404 " --dmenu0 like --dmenu, but input is NUL separated\n"405 " instead of newline separated\n"406 " --index print selected entry's index instead of of the \n"407 " entry's text (dmenu mode only)\n"408+ " --with-nth=N display the N:th column (tab separated) of each\n"409+ " input line (dmenu only)\n"410 " -R,--no-run-if-empty exit immediately without showing UI if stdin\n"411 " is empty (dmenu mode only)\n"412 " --log-level={info|warning|error|none}\n"413 " log level (warning)\n"325 unmodified lines739 #define OPT_PLACEHOLDER_COLOR 293740 #define OPT_SEARCH_TEXT 294741 #define OPT_COUNTER 295742 #define OPT_HIDE_WHEN_PROMPT_EMPTY 296743+ # define OPT_DMENU_WITH_NTH 297744 745 static const struct option longopts[] = {746 {"config", required_argument, 0, OPT_CONFIG},747 {"check-config", no_argument, 0, OPT_CHECK_CONFIG},59 unmodified lines807 {"dmenu", no_argument, 0, 'd'},808 {"dmenu0", no_argument, 0, OPT_DMENU_NULL},809 {"no-run-if-empty", no_argument, 0, 'R'},810 {"index", no_argument, 0, OPT_DMENU_INDEX},811+ {"with-nth", required_argument, 0, OPT_DMENU_WITH_NTH},812 813 /* Misc */814 {"log-level", required_argument, 0, OPT_LOG_LEVEL},815 {"log-colorize", optional_argument, 0, OPT_LOG_COLORIZE},50 unmodified lines866 bool dmenu_enabled_set:1;867 bool dmenu_mode_set:1;868 bool dmenu_exit_immediately_if_empty_set:1;869 bool dmenu_delim_set:1;870+ bool dmenu_with_nth_set:1;871 bool layer_set:1;872 bool no_exit_on_keyboard_focus_loss_set:1;873 bool render_workers_set:1;874 bool match_workers_set:1;665 unmodified lines1540 cmdline_overrides.conf.dmenu.mode = DMENU_MODE_INDEX;1541 cmdline_overrides.dmenu_mode_set = true;1542 break;1543 1544+ case OPT_DMENU_WITH_NTH:1545+ if (sscanf(optarg, "%u", &cmdline_overrides.conf.dmenu.render_column) != 1) {1546+ fprintf(1547+ stderr,1548+ "%s: invalid with-nth value (must be an integer)\n",1549+ optarg);1550+ return EXIT_FAILURE;1551+ }1552+ cmdline_overrides.dmenu_with_nth_set = true;1553+ break;1554+1555 case OPT_LOG_LEVEL: {1556 int lvl = log_level_from_string(optarg);1557 if (lvl < 0) {1558 fprintf(240 unmodified lines1799 if (cmdline_overrides.dmenu_mode_set)1800 conf.dmenu.mode = cmdline_overrides.conf.dmenu.mode;1801 if (cmdline_overrides.dmenu_exit_immediately_if_empty_set)1802 conf.dmenu.exit_immediately_if_empty = cmdline_overrides.conf.dmenu.exit_immediately_if_empty;1803+ if (cmdline_overrides.dmenu_with_nth_set)1804+ conf.dmenu.render_column = cmdline_overrides.conf.dmenu.render_column;1805 if (cmdline_overrides.conf.list_executables_in_path)1806 conf.list_executables_in_path = cmdline_overrides.conf.list_executables_in_path;1807 if (cmdline_overrides.render_workers_set)1808 conf.render_worker_count = cmdline_overrides.conf.render_worker_count;223 unmodified linesmodified:render.c+38 added
1059 unmodified lines1060 } else {1061 /* No newlines, use title as-is */1062 match->application->render_title = match->application->title;1063 }1064+1065+ if (render->conf->dmenu.enabled &&1066+ render->conf->dmenu.render_column > 0)1067+ {1068+ const char32_t *column = match->application->render_title;1069+1070+ for (unsigned int i = 0;1071+ i < render->conf->dmenu.render_column - 1;1072+ i++)1073+ {1074+ column = c32chr(column, U'\t');1075+1076+ if (column == NULL) {1077+ LOG_WARN("%ls: only %u column(s) available",1078+ (const wchar_t *)match->application->title, i + 1);1079+ column = U"";1080+ break;1081+ }1082+1083+ column++;1084+ }1085+1086+ char32_t *new_render_title = NULL;1087+ const char32_t *next_tab = c32chr(column, U'\t');1088+1089+ if (next_tab == NULL)1090+ new_render_title = xc32dup(column);1091+ else {1092+ const size_t len = next_tab - column;1093+ new_render_title = xmalloc((len + 1) * sizeof(char32_t));1094+ memcpy(new_render_title, column, len * sizeof(char32_t));1095+ new_render_title[len] = U'\0';1096+ }1097+1098+ if (match->application->render_title != match->application->title)1099+ free(match->application->render_title);1100+ match->application->render_title = new_render_title;1101+ }1102 }1103 1104 const int y = first_row + render_baseline(render) + idx * render->row_height;1105 386 unmodified lines