dsifford/yarn-completion

Does not automplete after colon

PaNaVTEC opened this issue ยท 41 comments

If I have the following scrips in my package.json:

scripts: {
dev:something: ",,.,,"
dev:another: "...."
}

When I type dev:s and press tab does not autocomplete dev:something

What version do you have? That should have been fixed in 0.3.0 99ec65d

UPDATED: never mind. This seems to be a bash thing
https://stackoverflow.com/questions/43058218/bash-completion-on-os-x-with-colons

For me it ends up repeating.

"scripts": {
  "test": "...",
  "test:client": "...",
  "test:server": "..."
}

Type te, tab, tab, tab

image

Then :, tab

image

It appends test: to the already completed test:

I'm using Version: 0.5.0, Yarn 1.1.0

@cdeutsch Might be an issue in an old version of bash. What version are you running?

I'm not able to reproduce the issue on my machine.

asciicast

That could be.

I'm using 3.2.57(1)-release (macOS Sierra 10.12.6)

Adding this to my .bash_profile fixed it for me

COMP_WORDBREAKS=${COMP_WORDBREAKS//:}

@cdeutsch Good to know. Thanks for posting your solution.

Also highly recommended:

$ brew install bash (and then follow the prompts to set as your login shell, e.g. $ chsh -s /path/to/bash4 yourusername)

Also unrelated but highly, highly recommended:

Replace those pesky BSD utils with their GNU counterparts: https://apple.stackexchange.com/a/69332

Same here, after adding COMP_WORDBREAKS=${COMP_WORDBREAKS//:} seems to work.

$ echo $COMP_WORDBREAKS 
"'><=;|&(:
$ COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
$ echo $COMP_WORDBREAKS 
"'><=;|&(

I am using arch linux with bash 4.4.12
It seems that here they have a way to handle colons: https://stackoverflow.com/questions/10528695/how-to-reset-comp-wordbreaks-without-affecting-other-completion-script

@PaNaVTEC Strange that you're having the issue on arch with bleeding edge bash. I'm also on arch linux most of the time and I do not have to add that...

Anyway, since this seems to be a common and recurring theme here, I'll probably just locally update COMP_WORDBREAKS during script execution and then revert it back before exiting so that this is fixed across the board.

I'll try to get to this when I get time. PRs also accepted.

Thanks for the workaround!

v0.5.1 should work now without having to adjust your system's globally set COMP_WORDBREAKS variable.

I just installed yarn completion using curl -L https://raw.githubusercontent.com/dsifford/yarn-completion/master/yarn-completion.bash > `brew --prefix`/etc/bash_completion.d/yarn and unfortunately experienced this bug. Using standard macos bash terminal and the downloaded file is v0.5.1.

With build and build:watch scripts in package.json, here's what happens:

type yarn bui + hit tab
โ†“
yarn build + beep

type :w + hit tab
โ†“
yarn build:build:watch

What could be causing such a behaviour?


UPD: I typed export COMP_WORDBREAKS=${COMP_WORDBREAKS//:} to the same terminal as a small experiment and the issue was gone. So it looks like the workaround mentioned by @cdeutsch is still needed even with 0.5.1.

@kachkaev very strange that you still needed to set COMP_WORDBREAKS globally. Setting it locally should overwrite the global value in the execution context, so no idea why that didn't happen in your case.

Thanks for the update.

Can it be that a fix requires export COMP_WORDBREAKS=... instead of just COMP_WORDBREAKS=...?

That would definitely work, but I don't think that is something that should be done by a third party script since that change will leak across the entire OS and could potentially break something.

Hey @kachkaev I think I might know why you were having those strange issues.

What's the output when you enter bind -v | grep skip in your terminal?

@dsifford it's empty ๐Ÿค”

macOS High Sierra 10.13.3 / bash

Hm...

Not 100% sure here, but it's clear that you're still using bash 3 (which, at the time of writing, is 9 years outdated).

In Bash 4, along with a host of other niceties, the readline library provides a variable called skip-completed-text which, when tabbing though completions in the middle of a word, skips the text you've already typed.

The reason why Mac OS is stuck at Bash 3 is because bash 4 changed to GPL v3 and mac can't ship that.

So, in short, to fix this issue for sure, and to make your life a whole lot simpler, I'd recommend just installing bash 4 using homebrew.

Hey @dsifford I'm using Archlinux as mentioned before in this issue, it ships with Bash 4.4 and I still have the same issue. Let me know if I can test anything for you

bash --version
GNU bash, version 4.4.19(1)-release (x86_64-unknown-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Output of bind -v:

$ bind -v | grep skip
set skip-completed-text off

Well, shoot. I have no idea then.

Are your dotfiles published online somewhere?

Cool... I'll take a look a bit later.

This is kind of a hail mary, so no promises that I actually turn up with something.

You're right! My bash --version on macOS was saying:

GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)
Copyright (C) 2007 Free Software Foundation, Inc.

After brew install bash and opening a new terminal, I got:

GNU bash, version 4.4.19(1)-release (x86_64-apple-darwin17.3.0)
Copyright (C) 2016 Free Software Foundation, Inc.

Although I still don't see any output in bind -v | grep skip, autocompletion after : works!

@kachkaev Glad to hear.

Make sure you follow the instructions that homebrew prints out after installing (related to changing your login shell) so that the changes persist through logins/logouts.

Otherwise, you'll be back with bash 3 next time you log in.

Nxt3 commented

Not sure what I'm doing wrong, but this still isn't working for me. I installed it through Homebrew following the steps exactly. bash --version yields GNU bash, version 4.4.19(1)-release (x86_64-apple-darwin16.7.0).

I've run bind -v | grep skip and that didn't fix it either.

Example of what I mean:

  • yarn lint: (should have :ts, :sass, :html as valid options)
  • yarn lint:s TAB
  • yarn lint:s

@Nxt3 Did you make sure to set bash 4 as your login shell?

bash --version might print 4.4.19 if bash is available in your PATH, but if it's not your login shell, the completions won't work.

You can check what shell you're currently running by entering this in your terminal...

$ echo "${BASH_VERSINFO[*]}"
Nxt3 commented

I did the following:

# Add the new shell to the list of legit shells
sudo bash -c "echo /usr/local/bin/bash >> /private/etc/shells"

# Change the shell for the user
chsh -s /usr/local/bin/bash

and still no dice.

I'm assuming you logged out and logged back in, correct?

Nxt3 commented

Nope ๐Ÿ™ƒ Sorry for wasting your time.

Haha not a waste of time at all @Nxt3!

I only knew to suggest that because I've been in your exact position in the past. ๐Ÿ˜Š

Glad it's now working well for you!

Nxt3 commented

@dsifford I think I spoke too soon. I've done a full reboot and it still isn't working. :|

Just the colon issue again or something else?

If just the colon issue, add COMP_WORDBREAKS=${COMP_WORDBREAKS//:} to your .bash_profile or .bashrc and give that a try

Nxt3 commented

That's not working either. It's still just the colon issue.

what's the output of echo "$COMP_WORDBREAKS" in your terminal?

Nxt3 commented

screen shot 2018-03-22 at 3 41 30 pm

Should work. No idea why it isn't to be honest.

Do you have a minimal package.json that I can try?

Hm, that works fine for me on my macbook.

Assuming you have the latest version of the completions installed, correct.

Also, I don't think this is written in the README yet which is my fault, but you should be using the latest version of bash-completion from homebrew, which is bash-completion@2 and not bash-completion.

Can you confirm those things?

Nxt3 commented

I'll upgrade to bash-completion@2 and let you know.

It's weird, because I have another script called yarn start:dist and suggestions on that one work. However, it is the only yarn start:* that is present--whereas the lint one has multiple--so maybe it has something to do with that.

Nxt3 commented

@dsifford I've updated to bash-completion@2 and it still isn't working.

Not sure what the issue could be then unfortunately. I'm running a MBP with high sierra and it works fine on my machine

Nxt3 commented

Would the yarn version matter at all? Only thing I can think of.

I was able to fix this by adding

export COMP_WORDBREAKS=${COMP_WORDBREAKS//:}

in my .bash_profile after all bash completions were setup.

I'm running bash 5.x and bash_completions 2.x.