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

Add filepath as an equivalent to filename which completes into subdirs. #251

Closed
wants to merge 3 commits into from

Conversation

peterebden
Copy link
Contributor

I have some cases where this was the behaviour I wanted; obviously users can implement this themselves but it seems pretty generally useful (probably as much so as Filename?).

…ectories.

I have some cases where this was the behaviour I wanted; obviously users can implement this themselves but it seems pretty generally useful (probably as much so as Filename?).
Copy link
Owner

@jessevdk jessevdk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to me that this should just be part of the Filename type?

@peterebden
Copy link
Contributor Author

Yup, makes sense!

completion.go Outdated
@@ -62,6 +63,11 @@ func completionsWithoutDescriptions(items []string) []Completion {
// prefix.
func (f *Filename) Complete(match string) []Completion {
ret, _ := filepath.Glob(match + "*")
if len(ret) == 1 {
if info, err := os.Stat(ret[0]); err == nil && info.IsDir() {
ret, _ = filepath.Glob(ret[0] + "/*")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there is only one file that is a dir here too? I think this should just recurse? Since this has been waiting so long, I'll make the change. Thanks for contributing!!

@jessevdk
Copy link
Owner

Sorry this all took so long, I've been thinking a bit more about it though and I think we should do what bash does instead. Meaning, if it's a single directory, it should complete to <dir>/. Then the next completion run it will complete files in the directory. This way you can still complete to the dir easily if that's your goal, but also complete down into the files in the dir.

@jessevdk jessevdk closed this Sep 23, 2018
@jessevdk
Copy link
Owner

Merged through here #272, let me know if this doesn't really solve your problem.

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

Successfully merging this pull request may close these issues.

2 participants