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

Directory/file completion broken for files/dirs with spaces #74

Closed
gevhaz opened this issue Apr 23, 2022 · 3 comments · Fixed by #81
Closed

Directory/file completion broken for files/dirs with spaces #74

gevhaz opened this issue Apr 23, 2022 · 3 comments · Fixed by #81
Assignees

Comments

@gevhaz
Copy link

gevhaz commented Apr 23, 2022

The problem

If I use shtab.DIRECTORY or shtab.FILE and try to complete a directory with spaces in the name, I just get a jumble of words as suggestions and the directory name isn't completed.

How to reproduce

Here is the relevant part of the python code

        parser.add_argument(
            "-d",
            "--directory",
            action="store",
            required=True,
            dest="dir",
            help="directory",
        ).complete = shtab.DIRECTORY  # type: ignore

Create a directory with spaces in the name:

$ mkdir "dir with many spaces"
$ ls
dir with many spaces

Completion without typing part of the word first yields a list of the words in the directory name:

$ my_script -d
dir     many    spaces  with

Nothing is completed when pressing tab.

Add the start of the directory name:

$ my_script -d di
dir     many    spaces  with

Same result.

More info

Compgen, seems to handle it just fine:

$ compgen -d
dir with many spaces
$ compgen -d dir
dir with many spaces

Here's a relevant part of the generated completion script:

_shtab_my_script__d_COMPGEN=_shtab_compgen_dirs
...
# $1=COMP_WORDS[1]
_shtab_compgen_dirs() {
  compgen -d -- $1  # recurse into subdirs
}

So I can't see where it goes wrong. Seems to work fine when I do it manually. I'm happy to test stuff if you have suggestions.

@casperdcl
Copy link
Collaborator

Yup, looks like a bug

@casperdcl
Copy link
Collaborator

Should be fixed in shtab>=1.5.5

@gevhaz
Copy link
Author

gevhaz commented Jun 18, 2022

Thank you! It works :)

casperdcl added a commit to brentyi/shtab that referenced this issue Oct 29, 2022
casperdcl added a commit to brentyi/shtab that referenced this issue Oct 29, 2022
casperdcl added a commit to brentyi/shtab that referenced this issue Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants