neogeographica / chaintool

WIP
GNU General Public License v3.0
0 stars 0 forks source link

would be nice to have filepath completion for some placeholder values #18

Closed neogeographica closed 3 years ago

neogeographica commented 3 years ago

E.g. after typing "map=/home" use tabs here and there to help autocomplete the whole path.

Problem is, there's no metadata to tell the system that a particular placeholder value is a filepath, and I don't know if trying to introduce that is the right thing to do. Another approach would be to be sneaky with some heuristics like checking for a leading slash or tilde.

neogeographica commented 3 years ago

Could just delegate to _chaintool_file_completions if trying to autocomplete after an equals symbol. Most of the time this wouldn't be a filepath value, but in that case why even try to use autocomplete?

The fiddly part here may be properly detecting "autocomplete after an equals symbol". Last time I looked at this I saw different bash versions behaving differently, as to whether the "=" is part of the current word or not.

neogeographica commented 3 years ago

Testing behavior for that. Simple completion func:

_testcomp()
{
    local PREV="${COMP_WORDS[$COMP_CWORD-1]}"
    local CUR="${COMP_WORDS[$COMP_CWORD]}"
    echo
    echo "PREV: $PREV"
    echo "CUR: $CUR"
    echo
}
complete -F _testcomp testcomp

On macOS with bash 5.1.4(1)-release:

Will test later with bash 4.

neogeographica commented 3 years ago

Same as above with bash 4.4.20(1)-release on Ubuntu.

With bash 3.2.57(1) on macOS:

bash 3 has other completion issues too though, so it's fine IMO just to not have this particular thing work on bash 3 either.