Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash completion inside backticks or $() using complete

Consider this one-liner to activate bash completion for foobar:

complete -F _known_hosts foobar

This shows a list of completion options for

> foobar <TAB> <TAB>

but not for

> $(foobar <TAB> <TAB>

or

> `foobar <TAB> <TAB>

I think it makes a lot of sense to have tab completion for expressions that are inside backticks or $(). How can I make this work?

like image 816
mnieber Avatar asked Dec 07 '16 13:12

mnieber


People also ask

What key is used for bash completion?

Bash completion is a bash function that allows you to auto complete commands or arguments by typing partially commands or arguments, then pressing the [Tab] key. This will help you when writing the bash command in terminal.

How can I tell if I have bash completion?

You can use the complete command with the -p option to get a list of all or specific completions.

How do bash completions work?

Bash completion is a functionality through which Bash helps users type their commands more quickly and easily. It does this by presenting possible options when users press the Tab key while typing a command.


2 Answers

Try these:

Esc+/ (to complete the filename i.e. you have entered some characters

Ctrl+x+/ (to list possible filenames - do note; there are 2 +)

(I was searching for an answer to this question for a long time; then got this from bash man page :-))

like image 177
mnt Avatar answered Sep 28 '22 14:09

mnt


Bash completion inside back ticks or $() is called "command substitution".

So it looks similar to a few other questions:

https://unix.stackexchange.com/questions/152328/bash-tab-completion-fails-inside-of-command-substitution

https://askubuntu.com/questions/571544/bash-tab-completion-bash-unexpected-eof-while-looking-for-matching-bash/576983#576983

https://unix.stackexchange.com/questions/152328/bash-tab-completion-fails-inside-of-command-substitution

For Debian-based linux operating systems like Ubuntu, the problem is a known bug from the bash-completion application: /usr/share/bash-completion/completions

You can report an issue here:

https://github.com/scop/bash-completion/issues

like image 32
rossetta Avatar answered Sep 28 '22 15:09

rossetta