In bash is there a quick way to do tab auto-completion based on the middle of a word.
So for example, if I have these files in a directory:
001_apple.txt 002_pear.txt 003_dog.txt
I would like to type the sequence: *d<TAB>
to auto-complete 003_dog.txt.
Can this be done in bash? Is it easier to do in other shells?
The programmable completion feature in Bash permits typing a partial command, then pressing the [Tab] key to auto-complete the command sequence. [1] If multiple completions are possible, then [Tab] lists them all.
From the bash manual: The backslash character '\' may be used to remove any special meaning for the next character read and for line continuation.
If you don't want to use echo repeatedly to create new lines in your shell script, then you can use the \n character. The \n is a newline character for Unix-based systems; it helps to push the commands that come after it onto a new line.
Use Tab to autocomplete the names of directories and files while in the command line.
Try ESC-g for glob expansion.
And you should always install the bash-completion package (included by default often, but you need to source it in your bash profile script).
Looks like zsh does this plus quite a bit more. See: expand-or-complete-prefix and COMPLETE_IN_WORD options.
Fish also does this really nicely out-of-the-box.
ls *d*<TAB>
works in bash. Not sure if that's what Ben meant. ls
could of course be any other command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With