xonsh / py-bash-completion

A framework for accessing bash completions from Python
BSD 3-Clause "New" or "Revised" License
19 stars 4 forks source link

Fixes for quotes in bash completer #8

Closed gforsyth closed 6 years ago

gforsyth commented 6 years ago

There were several issues popping up in xonsh that I traced back to here.

The current behavior of this code in xonsh right now is as follows:

mkdir -p "this is a test"  # in otherwise empty dir to avoid multiple
matches
ls th[tab] -> ls t'this is a test/'
ls 'th[tab] -> ls 't'this is a test/'
ls "th[tab] -> no results

Initially the leading double-quote seemed to work in xonsh but that is actually the bash completer failing completely and then xonsh falling back on to the path completer which works correctly for this completion. Wild.

If I directly import the bash_completions function in the same test directory with that folder name and call it directly:

gil@bad_cat ~/tmp 🐚  bash_completions('"th', 'ls "th', 5, 6)
(set(), 0)
gil@bad_cat ~/tmp 🐚  bash_completions("'th", "ls 'th", 5, 6)
({"'this is a test/'"}, 1

Note that the double-quoted lead returns nothing. Also, the single-quoted lead says that the number of characters to strip off of the prefix is 1, which will leave a leading 't as evidenced above.

So, two main fixes in here:

The last remaining bit of weirdness that I haven't tracked down yet is that the bash completer script always returns quoted paths using single quotes, no matter if the original explicit leading quote is single or double.

That said, this is still an improvement and also seems to fix some of the weird readline issues we were seeing, too.

gforsyth commented 6 years ago

Also, hat-tip to @battaglia01 for noticing the disparate behavior between quote types!

scopatz commented 6 years ago

Thanks @gforsyth and @battaglia01! This is great!

The last remaining bit of weirdness that I haven't tracked down yet is that the bash completer script always returns quoted paths using single quotes, no matter if the original explicit leading quote is single or double.

Yeah that is odd, but perhaps unsuprising :)