sio / bash-complete-partial-path

Enhanced file path completion in bash (like in zsh)
Apache License 2.0
54 stars 2 forks source link

Inconsistent with default completion behavior in simpler cases #10

Closed sio closed 4 years ago

sio commented 4 years ago

Reported by @geekscrapy in comments:

Can confirm it's working now. All except when I do the following: cd /etc

...And then TAB. "etc" is a directory and I would expect it to add the slash and then TAB again to start looping over the files and directories within "etc". But it just stops and doesn't autocomplete. It does this with all directories

I confirm the reported behavior. Issue affects only directory completion.

File completion (try ls) works almost as expected, but double slashes should be dropped.

sio commented 4 years ago

@geekscrapy, now completion should work as you described

geekscrapy commented 4 years ago

Thanks, I just tested and I get odd behavior - using commit 7885c8e. The following gets printed to the terminal as part of the auto-complete:

$ cd /Vol<tab>/var/folders/gy/tk3qzc8d7_zc1kdm1yzl58yszv_8fz/T/bcpp_pipe.654uF2X9
umes/
/Volumes/Macintosh  HD

^ The last line is what I would expect (as the second option to complete), and the unexpected behavior being the printout of the following path one the first time is pressed. As you can see, "umes/" is the correct first auto suggestion, which is printed after the random path.

/var/folders/gy/tk3qzc8d7_zc1kdm1yzl58yszv_8fz/T/bcpp_pipe.654uF2X9 umes/

sio commented 4 years ago

I understand what that garbage output means, but there are multiple places where it could've come from. Since this does not happen on my machines (Linux, Windows), it may be related to some little differences in GNU and BSD tooling. Can you help me with debugging?

geekscrapy commented 4 years ago
$ cd /Vol+ _bcpp_complete directory
+ local WILDCARDS ACTION LINE OPTION INPUT QUOTE
+ ACTION=directory
+ [[ _directory == \_\-\d ]]
+ [[ 1 -ge 0 ]]
+ INPUT=/Vol
+ [[ / == \' ]]
+ [[ / == \" ]]
+ QUOTE=
+ COMPREPLY=()
+ compopt -o nospace
+ compopt -o bashdefault
+ compopt -o default
+ [[ -e /Vol ]]
++ _bcpp_put_wildcards /Vol
++ local PROCESSED TILDE_EXPANSION INPUT
++ INPUT=/Vol
+++ echo /Vol
+++ gsed -Ee 's:([^\*\~])/:\1*/:g;
                s:([^\/\*])$:\1*:g;
                s:^(\~[^\/]*)\*\/:\1/:;
                s:(\.+)\*/:\1/:g;
                s:(^|/)(\$[^/]+)\*(/|$):\2\3:g'
++ PROCESSED='/Vol*'
+++ printf %q '/Vol*'
+++ gsed -e 's:^\\\~:~:g' -Ee 's:(^|/)\\(\$):\1\2:g'
++ eval 'TILDE_EXPANSION=/Vol\*'
+++ TILDE_EXPANSION='/Vol*'
++ [[ /Vol =~ ^/[a-zA-Z]/.* ]]
++ echo '/Vol*'
+ WILDCARDS='/Vol*'
+ local pipe
+ pipe=/var/folders/gy/tk3qzc8d7_zc1kdm1yzl58yszv_8fz/T/bcpp_pipe.QnXEffjK
+ [[ -z /var/folders/gy/tk3qzc8d7_zc1kdm1yzl58yszv_8fz/T/bcpp_pipe.QnXEffjK ]]
+ mkfifo -m 600 /var/folders/gy/tk3qzc8d7_zc1kdm1yzl58yszv_8fz/T/bcpp_pipe.QnXEffjK
+ local monitor
+ [[ himvxBHs == *m* ]]
+ monitor=yes
+ [[ yes == yes ]]
+ set +m
+ _bcpp_silent_bg _bcpp_compgen '/Vol*' /var/folders/gy/tk3qzc8d7_zc1kdm1yzl58yszv_8fz/T/bcpp_pipe.QnXEffjK
+ disown
+ return 0
+ local 'wildcards=/Vol*'
+ local pipe=/var/folders/gy/tk3qzc8d7_zc1kdm1yzl58yszv_8fz/T/bcpp_pipe.QnXEffjK
+ compgen -G '/Vol*' '/Vol*'
+ read -r -d '
' LINE
+ [[ _directory == \_\d\i\r\e\c\t\o\r\y ]]
+ [[ ! -d /Volumes ]]
+ [[ -z /Volumes ]]
+ [[ -z '' ]]
++ printf %q /Volumes
+ LINE=/Volumes
+ COMPREPLY+=("$LINE")
+ read -r -d '
' LINE
+ rm -v /var/folders/gy/tk3qzc8d7_zc1kdm1yzl58yszv_8fz/T/bcpp_pipe.QnXEffjK
/var/folders/gy/tk3qzc8d7_zc1kdm1yzl58yszv_8fz/T/bcpp_pipe.QnXEffjK
+ [[ yes == yes ]]
+ set -m
umes
sio commented 4 years ago

Aha, I see. Looks like you've set up a handy alias for rm :) I'll add a workaround for such cases, you don't need to change your configuration.

sio commented 4 years ago

I fixed this in issue-10 branch and added automated tests for this case. Please try the updated version and let me know if it's ok to merge :)

geekscrapy commented 4 years ago

Looks to have fixed it! 👍

sio commented 4 years ago

Ok, I've merged the changes into master