joshuto icon indicating copy to clipboard operation
joshuto copied to clipboard

Better support for autocompletion

Open sushi-shi opened this issue 3 years ago • 2 comments
trafficstars

Currently auto-completion is very simple, it expects the first word to be a command and next words to be files. This is already wrong, as some commands are made of multiple words (sort reverse) and what's more some commands do not accept files as parameters to begin with, so we do not need auto-completion for them. And other commands accept only folders, so autocompleting files should be avoided.

I propose to either add a simple specification, which every command should implement, to aid with autocompletion. Something akin to:

struct Command {
    spec: Specifiaction
    ...
}

struct Specification {
    params: Vec<(&'static str, Specification)>, // to cover `sort reverse`, `cd ..` and `cd -`.
    file_ty: Option<(FileTy, usize)>, // usize to show how many files the command might accept
}

enum FileTy {
    Any,
    Directories,
    FIles, 
}

This specification is in no way complete, but it covers the most general cases, which I think should suffice for now. Or make Command implement autocompleting interface through traits. (Possibly with a default implementation).

After we decide what to do (and whether to do anything at all), I will be willing to implement it.

sushi-shi avatar Jun 26 '22 12:06 sushi-shi

Also open_with requires current programs in PATH for auto-completion

sushi-shi avatar Jun 26 '22 19:06 sushi-shi

I agree that autocompletion needs much more work. :+1:

I'm kind of busy at the moment, but I'm definitely open to discussing how we want to go about designing and implementing this. :)

kamiyaa avatar Jun 27 '22 19:06 kamiyaa