dsifford / yarn-completion

Bash completion for Yarn
MIT License
277 stars 25 forks source link

`yarn why` includes a leading slash and also `.bin` #7

Closed elyscape closed 7 years ago

elyscape commented 7 years ago

If I type yarn why and then try to tab complete, it gives me a list that looks like this:

/.bin
/@types
/URIjs
/abab
[snip]

There are two problems with this. The first is that each item has a leading slash. This is because I am running on macOS, which uses BSD find, which includes the search path verbatim in the results. Running the find command used in the script yields these results:

$ find node_modules/ -maxdepth 1 -type d | sort
node_modules/
node_modules//.bin
node_modules//@types
node_modules//URIjs
node_modules//abab
[snip]

This can be easily fixed by changing the command to use node_modules:

$ find node_modules -maxdepth 1 -type d | sort
node_modules
node_modules/.bin
node_modules/@types
node_modules/URIjs
node_modules/abab
[snip]

By adding -mindepth 1, we don't have to even think about the folder itself:

$ find node_modules -maxdepth 1 -mindepth 1 -type d | sort
node_modules/.bin
node_modules/@types
node_modules/URIjs
node_modules/abab
[snip]

The other issue is that .bin is included in the list, and it really probably shouldn't be. This can be handled by adding -not -name .bin to the arguments:

$ find node_modules -maxdepth 1 -mindepth 1 -type d -not -name .bin | sort
node_modules/@types
node_modules/URIjs
node_modules/abab
[snip]
dsifford commented 7 years ago

@elyscape Thanks for such an awesome issue report! Seriously, kudos! πŸ™Œ

I'm using GNU utils, as I think you've probably guessed, so that's probably why this one fell through the cracks.

I'll get a fix out shortly πŸ˜„

elyscape commented 7 years ago

@dsifford I should note that having sort in the pipeline isn't necessary. Bash will sort the completions you provide it. I only put it in my commands to ensure that the output on the command line matched the output from the tab completion.