Bash: show progress indicator during long autocomplete

I have an autocompletion bash function that accesses a database to provide possible terminations of the current command line in bash. It takes about 3 seconds to complete, and during this time the user has no indication that he caused autocomplete, prompting him to press TAB again, which will lead to the fact that autocomplete may be launched several more times.

Is it possible to manipulate the command line to show that something is being done as soon as autocomplete begins? For example, when I press TAB twice after the foo command, I would like to immediately do the following:

 $ foo autocompleting... 

and then after the possible completions are determined, change to:

 $ foo bar baz jazz 

Alternatively, if I type foo j and press TAB once, the following:

 $ foo j autocompleting... 

should be changed to

 $ foo jazz 

without additional text under it, as expected.

The next step would be to consider the possibility of obtaining dynamic output when starting autocomplete, for example, printing characters \ | / - \ | / - in one place, as if the line rotated in place - visually indicate that something is happening. Is it possible?

+7
bash autocomplete
source share
1 answer

Of course, perhaps I think you will find everything you need in this answer (so this can be considered a duplicate question): Using BASH to display a progress (work) indicator

Your question is slightly different in that you want to delete the counter and then output the results. Thus, you can consider inverting the process that is specified. In other words, run your counter, and then it can be explicitly killed when your autocomplete function is finished (but before outputting the results, if possible for your code).

+1
source share

All Articles