mirror of https://github.com/ericonr/ef.git
Add intial query command line option.
It has an existing bug where the filter is only applied after the first user interaction.
This commit is contained in:
parent
69efce1d95
commit
a265492706
17
ef.c
17
ef.c
|
@ -43,9 +43,10 @@ int main(int argc, char **argv)
|
|||
setlocale(LC_ALL, "");
|
||||
|
||||
char delim = '\n';
|
||||
char *query = NULL;
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "01")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "01q:")) != -1) {
|
||||
switch (opt) {
|
||||
case '0':
|
||||
/* set delimiter to NUL char instead of newline */
|
||||
|
@ -54,6 +55,10 @@ int main(int argc, char **argv)
|
|||
case '1':
|
||||
/* ignored for compatibility with fzf */
|
||||
break;
|
||||
case 'q':
|
||||
/* initial query */
|
||||
query = optarg;
|
||||
break;
|
||||
default:
|
||||
exit(1);
|
||||
}
|
||||
|
@ -184,6 +189,16 @@ int main(int argc, char **argv)
|
|||
char *name = NULL;
|
||||
/* search tokens */
|
||||
struct str_array toks = { 0 };
|
||||
|
||||
if (query) {
|
||||
/* the intial query can be edited,
|
||||
* so it needs to be the same sort of storage */
|
||||
name = xmalloc(cap);
|
||||
strncpy(name, query, cap);
|
||||
add_entry(&toks, name);
|
||||
|
||||
name = NULL;
|
||||
}
|
||||
print_prompt(prompt, &toks, true);
|
||||
|
||||
/* index inside set of matches */
|
||||
|
|
Loading…
Reference in New Issue