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

Installing extensions from a script #118

Closed
elentok opened this issue Oct 11, 2018 · 7 comments
Closed

Installing extensions from a script #118

elentok opened this issue Oct 11, 2018 · 7 comments

Comments

@elentok
Copy link

elentok commented Oct 11, 2018

Hi,

I'm using a script in my dotfiles to install neovim and all of the plugins I need.

How can I install a Coc extension in a script?

I tried several options:

nvim "+CocInstall $extensions"
nvim --headless "+CocInstall $extensions"
nvim --headless "+CocInstall $extensions" +qall

The first one works but doesn't close nvim afterwards (so the install script can't run unattended),
the second one remains blank and the third exits immediately.

For reference to install vim-plug plugins I run:

nvim --headless +PlugInstall +UpdateRemotePlugins +qall

If I just go to ~/.config/coc/extensions and run yarn add $extensions will that be enough? or does coc register the extensions somewhere else?

Thanks for all the great work you're doing, I love this plugin! 👍

@chemzqm
Copy link
Member

chemzqm commented Oct 11, 2018

If I just go to ~/.config/coc/extensions and run yarn add $extensions will that be enough?

Yes, that's all you need to do, except that the location is different on windows.

does coc register the extensions somewhere else.

Is's possible for a vim plugin to regist custom extension root, then you need to use a plugin manager to install that plugin, but none of current extensions is vim plugin right now.

@elentok
Copy link
Author

elentok commented Oct 11, 2018

Cool, thanks!

@ardydavari
Copy link

ardydavari commented May 17, 2020

I wanted to run this in a docker build file, and I found a hack that worked: RUN timeout 1m nvim --headless +CocInstall; exit 0

@Trainraider
Copy link

I found a good solution: nvim --headless +"CocInstall -sync $extensions|qa"

@nachovizzo
Copy link

None of the solutions above works in my case. I've defined coc_global_extensions and inside vim :CocInstall works just fine. The problem is that I'm trying to run an unattended script where yarn is not available (but npm is)

Is there anything I'm missing to try?

I wish I could do

nvim --headless +CocInstall +qall

But exits right away

@nachovizzo
Copy link

In the meantime this is doing the job for me:

mkdir -p ~/.config/coc/extensions && cd ~/.config/coc/extensions
if [ ! -f package.json ]; then
  echo '{"dependencies":{}}' >package.json
fi
COC_EXTENSIONS=$(nvim --headless -c 'echo coc_global_extensions' +qa 2>&1 | awk -v RS="'" '!(NR%2)')
npm install $(echo $COC_EXTENSIONS) --global-style --ignore-scripts --no-bin-links --no-package-lock --only=prod

@Freed-Wu
Copy link

Freed-Wu commented Nov 11, 2022

if len(g:coc_global_extensions) > 18, it will

❯ vi --headless -c "call coc#util#install_extension(['-sync'] + g:coc_global_extensions) |qa"
Error on request (installExtensions): Vim(return):E699: Too many arguments%
❯ vi --headless -c'echo g:coc_global_extensions | quit'
cwd: /home/wzy/.config/coc
['coc-highlight', 'coc-ci', 'coc-pydocstring', 'coc-diagnostic', 'coc-spell-checker', 'coc-markdownlint', 'coc-prettier', 'coc-tasks', 'coc-vimtex', 'coc-emmet', 'coc-snippets', 'coc-translator', 'coc-zi', 'coc-marketplace', 'coc-lists', 'coc-yank', 'coc-git', 'coc-gist', 'coc-gitignore', 'coc-dash-complete', 'coc-dot-complete', 'coc-just-complete', 'coc-bibtex', 'coc-dictionary', 'coc-tag', 'coc-word', 'coc-emoji', 'coc-syntax', '@yaegassy/coc-marksman', 'coc-webview', 'coc-markdown-preview-enhanced', 'coc-json', 'coc-yaml', 'coc-toml', 'coc-xml', 'coc-svg', 'coc-html', 'coc-clang-format-style-options', 'coc-docker', 'coc-sql', 'coc-sh', 'coc-vimlsp', 'coc-texlab', 'coc-jedi', 'coc-pyright', 'coc-lua', 'coc-solargraph', 'coc-clangd', 'coc-tabnine']%

So tail -n1 is needed.

And I prefer sed than awk:

git clone --depth=1 https://github.com/Shougo/dein.vim \
	~/.local/share/nvim/repos/github.com/Shougo/dein.vim &&
	vi -c'call dein#update() | quit' &&
	mkdir -p ~/.config/coc/extensions &&
	echo '{"dependencies": {}}' >~/.config/coc/extensions/package.json &&
	npm install -C ~/.config/coc/extensions \
		$(vi --headless -c'echo g:coc_global_extensions | quit' 2>&1 | tail -n1 |
			sed "s=\(', '\|\['\|']\)=\n=g") &&
	mkdir -p ~/.config/coc/extensions/coc-gist-data &&
	echo '{"token": "gho_"}' >~/.config/coc/extensions/coc-gist-data/secret.json  # disable prompt

works for me.

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

No branches or pull requests

6 participants