Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mangled completion with tilde and Bash option 'failglob' #306

Closed
Maelan opened this issue Apr 27, 2019 · 4 comments
Closed

Mangled completion with tilde and Bash option 'failglob' #306

Maelan opened this issue Apr 27, 2019 · 4 comments

Comments

@Maelan
Copy link
Contributor

Maelan commented Apr 27, 2019

Completion of paths involving a tilde has become unusable since a recent system upgrade, presumably since Bash has been upgraded to version 5.0 (hence it might be related to issue #298, but symptoms differ). I identified that the issue only arises when Bash option failglob is set.

Configuration:

  • architecture x86-64
  • Linux 5.0.3-arch1-1-ARCH (Archlinux)
  • Bash 5.0.2(1)-release (from Archlinux’ package)
  • bash-completion 2.8.1 (from Archlinux’ package)

Steps to reproduce:

‹tab› represents pressing the tabulation key (for completion), ^C represents the Control+c shortcut (to abort the current command line).

# start with a clean environment and configuration:
$ env -i bash --norc --noprofile
$ ls -F ~
TEST/  more_dirs/  more_files.txt
# no bash-completion, 'failglob' off:
$ shopt -u failglob
$ cd ~/T‹tab›EST/^C
$ ls ~/T‹tab›EST/^C
# no bash-completion, 'failglob' on:
$ shopt -s failglob
$ cd ~/T‹tab›EST/^C
$ ls ~/T‹tab›EST/^C
# with bash-completion, 'failglob' off:
$ source /usr/share/bash-completion/bash_completion
$ shopt -u failglob
$ cd ~/T‹tab›EST/^C
$ ls ~/T‹tab›EST/^C
# with bash-completion, 'failglob' on:
$ shopt -s failglob
$ cd ~/T‹tab›EST/^C
$ ls ~/T‹tab›[bash: no match: \~/T
]EST/^C
$ \cd ~/T‹tab›[bash: no match: \~/T
]EST/^C

The expected completion always gets appended to the command line but, when failglob is on, an error message is also printed (hereinabove, shown between brackets for clarity):

bash: no match: \~/T

This is the error message printed by Bash when pathname expansion fails and failglob option is on. Note that the tilde is incorrectly escaped. This message is not appended to the command line, but it mangles the display.

This happens with many commands, including ls, mv, rm and any custom command, but not with cd. However \cd does trigger the error, even though there is no alias of that name.

@Maelan
Copy link
Contributor Author

Maelan commented Apr 27, 2019

I noticed another, more serious issue with tilde. This time, this is triggered by the Bash option nullglob. I suspect these are two manifestations of the same underlying bug.

Configuration: same

Steps to reproduce:

‹tab›‹tab› is double-pressing the tabulation key, so as to display all completion candidates.

# start with a clean environment and configuration:
$ env -i bash --norc --noprofile
$ ls -F ~
dir_in_home/  file_in_home
$ ls -F .
dir_in_currentdir/  file_in_currentdir
# no bash-completion, 'nullglob' off:
$ shopt -u nullglob
$ ls ~/‹tab›‹tab›
dir_in_home/  file_in_home
# no bash-completion, 'nullglob' on:
$ shopt -s nullglob
$ ls ~/‹tab›‹tab›
dir_in_home/  file_in_home
# with bash-completion, 'nullglob' off:
$ source /usr/share/bash-completion/bash_completion
$ shopt -u nullglob
$ ls ~/‹tab›‹tab›
dir_in_home/  file_in_home
# with bash-completion, 'nullglob' on:
$ shopt -s nullglob
$ ls ~/‹tab›‹tab›
dir_in_currentdir/  dir_in_home/  file_in_currentdir

As can be seen, when option nullglob is on, the completion candidates for ~/ are completely wrong: they mix the contents of the home directory with the contents of the current directory, and they miss the regular files from the home directory (in other words, candidates are the files which match either ~/*/ or * — in regard to the semantics of nullglob, I might see how * comes up, but I have a hard time explaining this ~/*/ with a slash appended…).

Again this happens with ls and most commands, but not cd… but it happens with \cd (this last one even has files in suggestions, although only directories should be suggested for cd completion).

@scop
Copy link
Owner

scop commented Apr 27, 2019

I don't expect it to necessarily make a difference, but please try out with the current master branch from here, or 2.9 (it was released earlier today). I'll get to this soonish unless someone beats me to it. In the meantime, see Troubleshooting in README.md.

@dsifford
Copy link

Update your arch packages and try again @Maelan. 2.9 seems to have done the trick for my issue in #298.

@Maelan
Copy link
Contributor Author

Maelan commented May 11, 2019

Looks like upgrading bash-completion to 2.9-1 (from Archlinux’ package) fixed both issues. Thanks!

Plus, oh my, my long-gone man completion came back to life. What a day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants