diff options
author | Phil Jones <philj56@gmail.com> | 2022-08-21 20:58:10 +0100 |
---|---|---|
committer | Phil Jones <philj56@gmail.com> | 2022-08-21 20:58:10 +0100 |
commit | faf685ca266d9cd3e2bb42d2ef105a5577cfcaf1 (patch) | |
tree | 26f64872c8d192413f2411c2ff6054e849799922 | |
parent | aeefb7cd446cbc32f6bd68f3f776a032979b3b92 (diff) |
Add --require-match option.
-rw-r--r-- | completions/tofi | 1 | ||||
-rw-r--r-- | doc/config | 5 | ||||
-rw-r--r-- | doc/tofi.5.md | 8 | ||||
-rw-r--r-- | doc/tofi.5.scd | 7 | ||||
-rw-r--r-- | src/config.c | 2 | ||||
-rw-r--r-- | src/main.c | 22 | ||||
-rw-r--r-- | src/tofi.h | 1 |
7 files changed, 42 insertions, 4 deletions
diff --git a/completions/tofi b/completions/tofi index 88988f9..f20cb33 100644 --- a/completions/tofi +++ b/completions/tofi @@ -42,6 +42,7 @@ _tofi() --hide-cursor --history --fuzzy-match + --require-match --drun-launch --hint-font --late-keyboard-init @@ -127,6 +127,11 @@ # Use fuzzy matching for searches. fuzzy-match = false + # If true, require a match to allow a selection to be made. If false, + # making a selection with no matches will print input to stdout. + # In drun mode, this is always true. + require-match = true + # If true, directly launch applications on selection when in drun mode. # Otherwise, just print the command line to stdout. drun-launch = false diff --git a/doc/tofi.5.md b/doc/tofi.5.md index 6eed96d..ba88c1b 100644 --- a/doc/tofi.5.md +++ b/doc/tofi.5.md @@ -260,6 +260,14 @@ options. > > Default: false +**require-match**=*true\|false* + +> If true, require a match to allow a selection to be made. If false, +> making a selection with no matches will print input to stdout. In drun +> mode, this is always true. +> +> Default: true + **drun-launch**=*true\|false* > If true, directly launch applications on selection when in drun mode. diff --git a/doc/tofi.5.scd b/doc/tofi.5.scd index cf605b3..31f8083 100644 --- a/doc/tofi.5.scd +++ b/doc/tofi.5.scd @@ -226,6 +226,13 @@ options. Default: false +*require-match*=_true|false_ + If true, require a match to allow a selection to be made. If false, + making a selection with no matches will print input to stdout. + In drun mode, this is always true. + + Default: true + *drun-launch*=_true|false_ If true, directly launch applications on selection when in drun mode. Otherwise, just print the path of the .desktop file to stdout. diff --git a/src/config.c b/src/config.c index 3cbb18b..5dff7f2 100644 --- a/src/config.c +++ b/src/config.c @@ -324,6 +324,8 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const tofi->use_history = parse_bool(filename, lineno, value, &err); } else if (strcasecmp(option, "fuzzy-match") == 0) { tofi->fuzzy_match = parse_bool(filename, lineno, value, &err); + } else if (strcasecmp(option, "require-match") == 0) { + tofi->require_match = parse_bool(filename, lineno, value, &err); } else if (strcasecmp(option, "drun-launch") == 0) { tofi->drun_launch = parse_bool(filename, lineno, value, &err); } else if (strcasecmp(option, "drun-print-exec") == 0) { @@ -811,6 +811,7 @@ static void usage() " --horizontal <true|false> List results horizontally.\n" " --history <true|false> Sort results by number of usages.\n" " --fuzzy-match <true|false> Use fuzzy matching for searching.\n" +" --require-match <true|false> Require a match for selection.\n" " --drun-launch <true|false> Launch apps directly in drun mode.\n" " --drun-print-exec <true|false> Print a command line in drun mode.\n" " This is now always the case,\n" @@ -858,6 +859,7 @@ const struct option long_options[] = { {"hide-cursor", required_argument, NULL, 0}, {"history", required_argument, NULL, 0}, {"fuzzy-match", required_argument, NULL, 0}, + {"require-match", required_argument, NULL, 0}, {"drun-launch", required_argument, NULL, 0}, {"drun-print-exec", required_argument, NULL, 0}, {"hint-font", required_argument, NULL, 0}, @@ -933,11 +935,22 @@ static void parse_args(struct tofi *tofi, int argc, char *argv[]) } } -static void do_submit(struct tofi *tofi) +static bool do_submit(struct tofi *tofi) { struct entry *entry = &tofi->window.entry; uint32_t selection = entry->selection + entry->first_result; char *res = entry->results.buf[selection].string; + + if (tofi->window.entry.results.count == 0) { + /* Always require a match in drun mode. */ + if (tofi->require_match || entry->drun) { + return false; + } else { + printf("%ls\n", entry->input); + return true; + } + } + if (entry->drun) { /* * TODO: This is ugly. The list of apps needs to be sorted @@ -948,7 +961,7 @@ static void do_submit(struct tofi *tofi) struct desktop_entry *app = desktop_vec_find(&entry->apps, res); if (app == NULL) { log_error("Couldn't find application file! This shouldn't happen.\n"); - return; + return false; } else { res = app->path; } @@ -966,6 +979,7 @@ static void do_submit(struct tofi *tofi) entry->results.buf[selection].string); history_save(&entry->history, entry->drun); } + return true; } int main(int argc, char *argv[]) @@ -1007,6 +1021,7 @@ int main(int argc, char *argv[]) | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT, .use_history = true, + .require_match = true, }; wl_list_init(&tofi.output_list); @@ -1432,8 +1447,7 @@ int main(int argc, char *argv[]) } if (tofi.submit) { tofi.submit = false; - if (tofi.window.entry.results.count > 0) { - do_submit(&tofi); + if (do_submit(&tofi)) { break; } } @@ -84,6 +84,7 @@ struct tofi { bool drun_launch; bool drun_print_exec; bool fuzzy_match; + bool require_match; char target_output_name[MAX_OUTPUT_NAME_LEN]; }; |