[PATCH] ash: perform autocompletion on builtin commands

Sven-Göran Bergh sgb-list+busybox at systemaxion.se
Sat Oct 25 09:05:57 UTC 2014


Hi,

On 10/24/2014 09:40 PM, John Spencer wrote:
> Sven-Göran Bergh wrote:
>> Just source /etc/bash_completion in either .bashrc or .profile.
>
> what would be the contents of this file, that make expansion of the
> tilde work ?  /etc/bash_completion is not installed on my box.

Sure tilde expansion works.

/etc/bash_completion is an ordinary shell script file containing
instruction sets for the completions that you want. It is commonly used
by bash. Personally I run debian, but I am sure most distros have it.
In debian /etc/bash_completion is a symlink to
/usr/share/bash-completion/bash_completion. It includes all files
in /etc/bash_completion.d, so you can pretty much pick and choose what
completions you want, or even write your own once.

In my embedded project I only use a minimal /etc/bash_completion for the
most basic stuff.

> (just to make sure we're talking about the same thing:
> $ ls ~/.s<TAB> should expand to ~/.ssh/ or /home/user/.ssh, but doesn't)

# ls ~/.s<TAB> gives me ~/.ssh/

> while we're at it, the other autocompletion thing ash doesn't support
> out-of-the-box is expansion of directories in the first position on the
> actual line.
> for example i want to run utils/foo.sh
> $ u<TAB>
> doesn't expand to utils/, whereas
> $ ./u<TAB>
> does.

Yes, it works exactly as i bash. It all depends on how may files you
want in /etc/bash_completion.d/. Ex. in the kernel source tree on my
system you can just:

# make <TAB><TAB>

and you get a list of all valid targets in the Makefile.

> would be nice if this could be enabled using some trick.

Check out the files .bashrc, .profile or their global cousins in /etc, 
in your working bash environment. Somewhere /etc/bash_completion
(or something similar) is sourced. Study the structure and just transfer
the parts you want to your ash environment. Then make sure you have
CONFIG_FEATURE_TAB_COMPLETION=y when you build BB.

Happy tweaking
/S-G

>> ash will pick it up and use it in the same way as bash.
>> Have never had any problem with this. Works like a charm.
>>
>> Brgds
>> /S-G
>>
>> On 10/24/2014 05:20 PM, John Spencer wrote:
>>> Matteo Croce wrote:
>>>> Refactor read_line_input to accept a list of strings which are
>>>> added byt the autocompletion suggestions.
>>>> Let ash pass the builtin command list to read_line_input to enable
>>>> completion of builtin commands as echo, printf, history, exec, etc.
>>>
>>> nice. could this mechanism be used to expand ~ to the contents of $HOME
>>> for autocompletion ? lack of this expansion is currently my major
>>> annoyance with ash and the reason i still use bash...
>>> _______________________________________________
>>> busybox mailing list
>>> busybox at busybox.net
>>> http://lists.busybox.net/mailman/listinfo/busybox
>>
>



More information about the busybox mailing list