dsifford / yarn-completion

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

Does not automplete after colon #9

Closed PaNaVTEC closed 6 years ago

PaNaVTEC commented 7 years ago

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

dsifford commented 7 years ago

What version do you have? That should have been fixed in 0.3.0 https://github.com/dsifford/yarn-completion/commit/99ec65d7cad1e97a0b933a3c4801e68c862df0d3

cdeutsch commented 7 years ago

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~

dsifford commented 7 years ago

@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

cdeutsch commented 7 years ago

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//:}
dsifford commented 7 years ago

@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

PaNaVTEC commented 7 years ago

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

dsifford commented 7 years ago

@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.

sechel commented 6 years ago

Thanks for the workaround!

dsifford commented 6 years ago

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

kachkaev commented 6 years ago

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.

dsifford commented 6 years ago

@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.

kachkaev commented 6 years ago

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

dsifford commented 6 years ago

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.

dsifford commented 6 years ago

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?

kachkaev commented 6 years ago

@dsifford it's empty 🤔

macOS High Sierra 10.13.3 / bash

dsifford commented 6 years ago

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.

PaNaVTEC commented 6 years ago

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
dsifford commented 6 years ago

Well, shoot. I have no idea then.

Are your dotfiles published online somewhere?

PaNaVTEC commented 6 years ago

Sure, https://github.com/panavtec/dotfiles

dsifford commented 6 years ago

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.

kachkaev commented 6 years ago

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!

dsifford commented 6 years ago

@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 6 years ago

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:

dsifford commented 6 years ago

@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 6 years ago

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.

dsifford commented 6 years ago

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

Nxt3 commented 6 years ago

Nope 🙃 Sorry for wasting your time.

dsifford commented 6 years ago

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 6 years ago

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

dsifford commented 6 years ago

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 6 years ago

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

dsifford commented 6 years ago

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

Nxt3 commented 6 years ago
screen shot 2018-03-22 at 3 41 30 pm
dsifford commented 6 years ago

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

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

Nxt3 commented 6 years ago

https://gist.github.com/Nxt3/e4a6f43833242b5405180518158191c6

dsifford commented 6 years ago

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 6 years ago

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 6 years ago

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

dsifford commented 6 years ago

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 6 years ago

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

jgornick commented 5 years ago

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.