fzy
terminal fuzzy finder picker
git clone https://9o.is/git/fzy.git
commit 2e81ceb4a51605340294e28cc4c0400c137b866f parent 978ba29db362b3d0d0cc2e7709063de4ef800ae1 Author: John Hawthorn <john.hawthorn@gmail.com> Date: Tue, 31 Jan 2017 18:13:27 -0800 Add -j option to control parallelism Diffstat:
| M | src/choices.c | | | 6 | +++++- |
| M | src/options.c | | | 10 | +++++++++- |
| M | src/options.h | | | 1 | + |
3 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/choices.c b/src/choices.c @@ -107,7 +107,11 @@ void choices_init(choices_t *c, options_t *options) { c->capacity = c->size = 0; choices_resize(c, INITIAL_CHOICE_CAPACITY); - c->worker_count = (int)sysconf(_SC_NPROCESSORS_ONLN); + if (options->workers) { + c->worker_count = options->workers; + } else { + c->worker_count = (int)sysconf(_SC_NPROCESSORS_ONLN); + } choices_reset_search(c); } diff --git a/src/options.c b/src/options.c @@ -15,6 +15,7 @@ static const char *usage_str = " -e, --show-matches=QUERY Output the sorted matches of QUERY\n" " -t, --tty=TTY Specify file to use as TTY device (default /dev/tty)\n" " -s, --show-scores Show the scores of each match\n" + " -j, --workers NUM Use NUM workers for searching. (default is number of CPU threads)\n" " -h, --help Display this help and exit\n" " -v, --version Output version information and exit\n"; @@ -44,13 +45,14 @@ void options_init(options_t *options) { options->num_lines = 10; options->scrolloff = 1; options->prompt = "> "; + options->workers = 0; } void options_parse(options_t *options, int argc, char *argv[]) { options_init(options); int c; - while ((c = getopt_long(argc, argv, "vhse:q:l:t:p:", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "vhse:q:l:t:p:j:", longopts, NULL)) != -1) { switch (c) { case 'v': printf("%s " VERSION " (c) 2014 John Hawthorn\n", argv[0]); @@ -80,6 +82,12 @@ void options_parse(options_t *options, int argc, char *argv[]) { case 'p': options->prompt = optarg; break; + case 'j': + if (sscanf(optarg, "%u", &options->workers) != 1) { + usage(argv[0]); + exit(EXIT_FAILURE); + } + break; case 'l': { int l; if (!strcmp(optarg, "max")) { diff --git a/src/options.h b/src/options.h @@ -10,6 +10,7 @@ typedef struct { unsigned int num_lines; unsigned int scrolloff; const char *prompt; + unsigned int workers; } options_t; void options_init(options_t *options);