diff --git a/doc/rofi-dmenu.5 b/doc/rofi-dmenu.5 index 297dc3f0..49c12e55 100644 --- a/doc/rofi-dmenu.5 +++ b/doc/rofi-dmenu.5 @@ -274,6 +274,21 @@ Position \fBrofi\fP over the window with the given X11 window ID. .PP Set ellipsize mode to start. So, the end of the string is visible. +.PP +\fB\fC\-display\-columns\fR + +.PP +A comma seperated list of columns to show. + +.PP +\fB\fC\-display\-column\-separator\fR + +.PP +The column separator. This is a regex. + +.PP +\fIdefault\fP: '\\t' + .SH RETURN VALUE .RS .IP \(bu 2 diff --git a/doc/rofi-dmenu.5.markdown b/doc/rofi-dmenu.5.markdown index 73ff2235..80c7e749 100644 --- a/doc/rofi-dmenu.5.markdown +++ b/doc/rofi-dmenu.5.markdown @@ -177,6 +177,16 @@ Position **rofi** over the window with the given X11 window ID. Set ellipsize mode to start. So, the end of the string is visible. +`-display-columns` + +A comma seperated list of columns to show. + +`-display-column-separator` + +The column separator. This is a regex. + +*default*: '\t' + ## RETURN VALUE diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index ebfb810b..42b8a371 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -239,21 +239,23 @@ static gchar *dmenu_format_output_string(const DmenuModePrivateData *pd, for (; splitted && splitted[ns]; ns++) { ; } + GString *str_retv = g_string_new(""); for (uint32_t i = 0; pd->columns && pd->columns[i]; i++) { unsigned int index = (unsigned int)g_ascii_strtoull(pd->columns[i], NULL, 10); - if (index < ns && index > 0) { - if (retv == NULL) { - retv = g_strdup(splitted[index - 1]); + if (index <= ns && index > 0) { + if (index == 1) { + g_string_append(str_retv, splitted[index - 1]); } else { - gchar *t = g_strjoin("\t", retv, splitted[index - 1], NULL); - g_free(retv); - retv = t; + g_string_append_c(str_retv, '\t'); + g_string_append(str_retv, splitted[index - 1]); } } } g_strfreev(splitted); - return retv ? retv : g_strdup(""); + retv = str_retv->str; + g_string_free(str_retv, FALSE); + return retv; } static inline unsigned int get_index(unsigned int length, int index) { @@ -818,4 +820,8 @@ void print_dmenu_options(void) { print_help_msg("-w", "windowid", "Position over window with X11 windowid.", NULL, is_term); print_help_msg("-keep-right", "", "Set ellipsize to end.", NULL, is_term); + print_help_msg("--display-columns", "", "Only show the selected columns", + NULL, is_term); + print_help_msg("--display-column-separator", "\t", + "Separator to use to split columns (regex)", NULL, is_term); }