tdenniston / bish

Bish is a language that compiles to Bash. It's designed to give shell scripting a more comfortable and modern feel.
MIT License
1.48k stars 36 forks source link

Declarative syntax for autocompletions #72

Open bschlenk opened 7 years ago

bschlenk commented 7 years ago

I've been thinking of something like this for a while, but I always focused on the idea of automating the autocompletion scripts. It would be really cool to come up with a declarative syntax for defining function arguments that could be compiled into programmable completion in bash.

Here is a contrived example of how a function in bish could be annotated:

def ls(file=None, **kwargs) {
    """
    @file: File= - the name of the file to ls
    @-l - enable long output
    @-a - include hidden files
    @--longopt - longer option for example
    """
    return /bin/ls file? **kwargs
}

This would enable the following behavior:

> ls <Tab>
file - the name of the file to ls
-l  - enable long output
-a  - include hidden files
--longopt - longer option for example

> ls -<Tab>
-l  - enable long output
-a  - include hidden files
--longopt - longer option for example

> ls --long<Tab>
> ls --longopt
> ls --longopt<Tab>
--longopt - longer option for example

You can see a real world example of this type of autocompletion with tmux. Start some sessions and type tmux attach-session -<Tab>. I'm not sure if it would work to this degree in bash as I've only seen it in zsh, but it does offer some level of programmable autocompletion.

tdenniston commented 7 years ago

@bschlenk Interesting idea! Would the use-case be for using the bish REPL as a shell itself? Or are you thinking that the compiled bash script would register its autocompletion with the user's current shell (similar to Example J-1 in the document you linked)?

PS - you may have noticed, but I haven't had any time to devote to bish for quite a while now. If you'd like to take a crack at implementing this, please do!