packer.nvim
packer.nvim copied to clipboard
Use SSH to download plugins
In my network environment, using method below to download plug-ins often fails
git clone https://github.com/wbthomason/packer.nvim\
~/.local/share/nvim/site/pack/packer/start/packer.nvim
But, Ican use the following method
git clone [email protected]:wbthomason/packer.nvim.git\
~/.local/share/nvim/site/pack/packer/start/packer.nvim
So, I hope that the download method can be specified in the configuration file like below
require('packer').startup(function(use)
use {'wbthomason/packer.nvim', opt = true}
use '[email protected]:Lokaltog/vim-easymotion.git'
use '[email protected]:junegunn/vim-easy-align.git'
}
Thanks! We have some logic to check for this kind of case already: https://github.com/wbthomason/packer.nvim/blob/0d4ca4836c4c264b80584ae15d145e7235c05856/lua/packer/plugin_utils.lua#L24
Does the example you give just work out of the box? I haven't had a chance to test this yet on my end.
@kdurant For what it's worth, your example works for me already. However, my system is set up to clone everything using SSH already, so I'd still appreciate it if you could test your example on your setup and let me know how it goes. Thanks!
Sorry for adding new comment in this issue I add the following content in my ~/.ssh/config:
Host github
Hostname github.com
User git
IdentityFile ~/.ssh/PRIVATE_KEYFILE_NAME
Can support the clone with use { 'github:xxx/yyy' }
? :)
@c4dr01d Have you tried this and found that it does not work as expected?
@wbthomason I tried, packer report cannot access the address: https://github.com/github:xxx/yyy
Ah, ok. I think this might be a failing with our heuristic for guessing plugin URL type. As a workaround, you should be able to specify use '[email protected]:xxx/yyy'
.
@wbthomason I tried use '[email protected]:xxx/yyy'
, report not passed publickey authentication
@c4dr01d It sounds like you may have something wrong with your SSH/git setup, then - on my system, that kind of URL spec works as expected.
@wbthomason Because my SSH have lot of keypairs, but I rename my github keys to default name, anything is work
@wbthomason Maybe packer can add the ~/.ssh/config configuration reader?
Sorry, I'm not quite sure what you mean. What would you expect this configuration reader to do?
@wbthomason I expected packer can work like this: ~/.ssh/config:
Host github
Hostname github.com
User git
IdentityFile ~/.ssh/PRIVATE_KEY_NAME
init.lua
packer.startup(function()
use 'github:xxx/yyy'
end)
Sorry, to clarify: packer
does work with that URL specification format. I'm unfortunately not sure why your particular SSH config causes this issue - if you have thoughts on ways to improve packer
's git logic to handle this, I'm open to that, but I'm pretty hesitant to add in a SSH config parser for what seems to be a fairly niche case.
Not sure if this is relavent, it will be great to have an option of choosing between using ssh
or https
for for fetching the plugin
@winston0410 Usually, this is something you configure either globally with your git
config or by providing a specifically https
or ssh
URL for the plugin to packer
(rather than using the username/repo
form, which will default to whatever your global configu uses).
Thanks! We have some logic to check for this kind of case already:
https://github.com/wbthomason/packer.nvim/blob/0d4ca4836c4c264b80584ae15d145e7235c05856/lua/packer/plugin_utils.lua#L24
Does the example you give just work out of the box? I haven't had a chance to test this yet on my end.
This method can't solve problem.
@kdurant: Can you share the specification you used which led to that error? As I mentioned before (https://github.com/wbthomason/packer.nvim/issues/326#issuecomment-830313844), your original example "just works" on my system. Maybe this is a Windows issue?
For anybody who wants to use SSH to download plugins:
- Add you SSH key to Github account.
- Configure SSH: write something like this to ~/.ssh/config
Host github
Hostname github.com
User git
IdentityFile ~/.ssh/id_rsa.pub # your SSH public key file
- Set packer's
default_url_format
to[email protected]:%s
require("packer").startup({
function(use)
use("wbthomason/packer.nvim")
end,
config = {
git = {
default_url_format = "[email protected]:%s",
},
},
})
4.. Configure nvim-treesitter parsers' install_info.url
require("nvim-treesitter.install").prefer_git = true
local parsers = require("nvim-treesitter.parsers").get_parser_configs()
for _, p in pairs(parsers) do
p.install_info.url = p.install_info.url:gsub(
"https://github.com/",
"[email protected]:"
)
end
All code are tested on Debian 11.2.
It is difficult to download plugins from Github via HTTPS for Chinese users caused by China's Great Firewall. However, through SSH download seems to be feasible.
Thanks for this perfect plugin!
There is a way to make it so git always uses ssh in place of https if that is applicable. See https://stackoverflow.com/questions/32232655/go-get-results-in-terminal-prompts-disabled-error-for-github-private-repo
git config --global --add url."[email protected]:".insteadOf "https://github.com/"
Tested and this works on packer