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, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
char delim = '\n';
|
char delim = '\n';
|
||||||
|
char *query = NULL;
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "01")) != -1) {
|
while ((opt = getopt(argc, argv, "01q:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case '0':
|
case '0':
|
||||||
/* set delimiter to NUL char instead of newline */
|
/* set delimiter to NUL char instead of newline */
|
||||||
|
@ -54,6 +55,10 @@ int main(int argc, char **argv)
|
||||||
case '1':
|
case '1':
|
||||||
/* ignored for compatibility with fzf */
|
/* ignored for compatibility with fzf */
|
||||||
break;
|
break;
|
||||||
|
case 'q':
|
||||||
|
/* initial query */
|
||||||
|
query = optarg;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -184,6 +189,16 @@ int main(int argc, char **argv)
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
/* search tokens */
|
/* search tokens */
|
||||||
struct str_array toks = { 0 };
|
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);
|
print_prompt(prompt, &toks, true);
|
||||||
|
|
||||||
/* index inside set of matches */
|
/* index inside set of matches */
|
||||||
|
|
Loading…
Reference in New Issue