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

bash_completion script creates error on osx with zsh #2325

Closed
receter opened this issue Oct 16, 2020 · 5 comments · Fixed by #2393
Closed

bash_completion script creates error on osx with zsh #2325

receter opened this issue Oct 16, 2020 · 5 comments · Fixed by #2393
Labels
pull request wanted This is a great way to contribute! Help us out :-D shell: zsh

Comments

@receter
Copy link

receter commented Oct 16, 2020

For some users on macOSX with zsh this snippet creates an error:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

The error reads: complete:13: command not found: compdef

This happens because at the end of the bash_completion script bashcompinit is called but compinit is not yet called/loaded.

The following code fixes the issue, but maybe this can somehow be handled by the bash_completion script?

autoload -Uz compinit
compinit -i

export NVM_DIR="/Users/Aaron/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Operating system and version:

macOS 10.15.6

nvm debug output:

nvm --version: v0.33.8
$TERM_PROGRAM: Apple_Terminal
$SHELL: /bin/zsh
$HOME: /Users/andreasriedmuller
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.7.1 (x86_64-apple-darwin19.0)'
uname -a: 'Darwin 19.6.0 Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64 x86_64'
OS version: Mac 10.15.6 19G2021
curl: /usr/bin/curl, curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2
wget: not found
git: /usr/bin/git, git version 2.17.2 (Apple Git-113)
grep: /usr/bin/grep, grep (BSD grep) 2.5.1-FreeBSD
awk: /usr/bin/awk, awk version 20070501
sed: illegal option -- -
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
sed: /usr/bin/sed, 
cut: illegal option -- -
usage: cut -b list [-n] [file ...]
       cut -c list [file ...]
       cut -f list [-s] [-d delim] [file ...]
cut: /usr/bin/cut, 
basename: illegal option -- -
usage: basename string [suffix]
       basename [-a] [-s suffix] string [...]
basename: /usr/bin/basename, 
rm: illegal option -- -
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file
rm: /bin/rm, 
mkdir: illegal option -- -
usage: mkdir [-pv] [-m mode] directory ...
mkdir: /bin/mkdir, 
xargs: illegal option -- -
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
             [-L number] [-n number [-x]] [-P maxprocs] [-s size]
             [utility [argument ...]]
xargs: /usr/bin/xargs, 
nvm current: v10.15.3
which node: $NVM_DIR/versions/node/v10.15.3/bin/node
which iojs: iojs not found
which npm: $NVM_DIR/versions/node/v10.15.3/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v10.15.3
npm root -g: $NVM_DIR/versions/node/v10.15.3/lib/node_modules

nvm ls output:

        v6.14.1
        v8.15.1
       v10.14.2
->     v10.15.3
         system
default -> 10.15.3 (-> v10.15.3)
node -> stable (-> v10.15.3) (default)
stable -> 10.15 (-> v10.15.3) (default)
iojs -> N/A (default)
lts/* -> lts/dubnium (-> v10.15.3)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.0 (-> N/A)
lts/carbon -> v8.15.1
lts/dubnium -> v10.15.3

How did you install nvm?

install script

What steps did you perform?

nothing

What happened?

error showed up in PHPStorm Terminal

What did you expect to happen?

no error PHPStorm Terminal

Is there anything in any of your profile files that modifies the PATH?

export PATH="/usr/local/bin:$PATH"

@ljharb
Copy link
Member

ljharb commented Oct 16, 2020

https://github.com/nvm-sh/nvm/blob/master/bash_completion#L83-L93 should be handling that. What version of nvm are you using? (please always fill out the issue template; it's there for a reason)

@ljharb ljharb added needs followup We need some info or action from whoever filed this issue/PR. shell: zsh labels Oct 16, 2020
@receter
Copy link
Author

receter commented Oct 22, 2020

Hi @ljharb
I filled out the template, sorry for skipping.

Some people seem to have this issue, I answered my temporary (or final) solution on Stack Exchange https://apple.stackexchange.com/questions/296477/my-command-line-says-complete13-command-not-found-compdef/404470#404470

@ljharb
Copy link
Member

ljharb commented Oct 22, 2020

Thanks. Your solution should be unnecessary (https://github.com/nvm-sh/nvm/blob/master/bash_completion#L86-L93) so I'm not sure what the problem is.

I do note you're using an outdated version of nvm (0.33.8) - can you try installing the latest, v0.36.0?

@receter
Copy link
Author

receter commented Oct 30, 2020

Yea, there are some lines that are missing in my version of bash_completion. I am currently in homeoffice where I do not have this issue. I will try it when I am back at the office.

But I think the code might not work because compinit must be called before bashcompinit. Can be wrong though.

Zsh can handle bash completions functions. The latest development version of zsh has a function bashcompinit, that when run will allow zsh to read bash completion specifications and functions. This is documented in the zshcompsys man page. To use it all you need to do is run bashcompinit at any time after compinit. It will define complete and compgen functions corresponding to the bash builtins.

@ljharb
Copy link
Member

ljharb commented Oct 31, 2020

Ah! If that's indeed the case, then a PR to fix the bash_completion file would be appreciated.

@ljharb ljharb added pull request wanted This is a great way to contribute! Help us out :-D and removed needs followup We need some info or action from whoever filed this issue/PR. labels Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pull request wanted This is a great way to contribute! Help us out :-D shell: zsh
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants