packer.nvim icon indicating copy to clipboard operation
packer.nvim copied to clipboard

Use SSH to download plugins

Open kdurant opened this issue 3 years ago • 19 comments

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'
}

kdurant avatar Apr 29 '21 01:04 kdurant

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.

wbthomason avatar Apr 30 '21 05:04 wbthomason

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

wbthomason avatar Apr 30 '21 19:04 wbthomason

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 avatar Jun 09 '21 01:06 c4dr01d

@c4dr01d Have you tried this and found that it does not work as expected?

wbthomason avatar Jun 09 '21 17:06 wbthomason

@wbthomason I tried, packer report cannot access the address: https://github.com/github:xxx/yyy

c4dr01d avatar Jun 09 '21 23:06 c4dr01d

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 avatar Jun 11 '21 05:06 wbthomason

@wbthomason I tried use '[email protected]:xxx/yyy', report not passed publickey authentication

c4dr01d avatar Jun 22 '21 02:06 c4dr01d

@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 avatar Jun 22 '21 03:06 wbthomason

@wbthomason Because my SSH have lot of keypairs, but I rename my github keys to default name, anything is work

c4dr01d avatar Jun 22 '21 03:06 c4dr01d

@wbthomason Maybe packer can add the ~/.ssh/config configuration reader?

c4dr01d avatar Jun 22 '21 03:06 c4dr01d

Sorry, I'm not quite sure what you mean. What would you expect this configuration reader to do?

wbthomason avatar Jun 22 '21 03:06 wbthomason

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

c4dr01d avatar Jun 22 '21 03:06 c4dr01d

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.

wbthomason avatar Jun 28 '21 04:06 wbthomason

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 avatar Jul 23 '21 13:07 winston0410

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

wbthomason avatar Jul 23 '21 17:07 wbthomason

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. QQ截图20210831085200

kdurant avatar Aug 31 '21 00:08 kdurant

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

wbthomason avatar Sep 01 '21 22:09 wbthomason

For anybody who wants to use SSH to download plugins:

  1. Add you SSH key to Github account.
  2. 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
  1. 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!

kongjun18 avatar Feb 12 '22 11:02 kongjun18

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

Jakobeha avatar Apr 13 '22 00:04 Jakobeha