-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Resolve hostname set in ssh config #87
Comments
hi, @G0V1NDS, thanks for mention it, I'm looking into it. |
would you please help me with some details:
|
@linrongbin16 I will explain how I am using ssh config. SSH allows you to configure alias for the hosts.
I can use this alias in git remote like this: # ❯ git remotes
origin https://github.com/G0V1NDS/dotfiles-open.git (fetch)
origin https://github.com/G0V1NDS/dotfiles-open.git (push)
personal git@github-personal:G0V1NDS/dotfiles-open.git (fetch)
personal git@github-personal:G0V1NDS/dotfiles-open.git (push) Here We can get the same info from
Not sure |
hi @G0V1NDS , really thanks for your detailed example and education. I will first do some investigation into this (since I'm not expert in git alias), make sure the solution is good for most users. |
Hi @G0V1NDS , @joaodubas, Please use below config to map require("gitlinker").setup({
custom_rules = function(remote_url)
local rules = {
{
"^git@github-personal%.([_%.%-%w]+):([%.%-%w]+)/([_%.%-%w]+)%.git$",
"https://github.%1/%2/%3/blob/",
},
{
"^git@github-personal%.([_%.%-%w]+):([%.%-%w]+)/([_%.%-%w]+)$",
"https://github.%1/%2/%3/blob/",
},
}
for _, rule in ipairs(rules) do
local pattern = rule[1]
local replace = rule[2]
if string.match(remote_url, pattern) then
local result = string.gsub(remote_url, pattern, replace)
return result
end
end
return nil
end,
}) update: since #99 , you can simply config: require("gitlinker").setup({
override_rules = {
{
"^git@github-personal%.([_%.%-%w]+):([%.%-%w]+)/([_%.%-%w]+)%.git$",
"https://github.%1/%2/%3/blob/",
},
{
"^git@github-personal%.([_%.%-%w]+):([%.%-%w]+)/([_%.%-%w]+)$",
"https://github.%1/%2/%3/blob/",
},
}
}) |
@linrongbin16 Thanks for a quick solution, really appreciate it.
Tweaks made:
I would still prefer a solution which utilises the ssh config so user won't need to define a override rule as the information is already available in ssh config. |
@linrongbin16 A quick look at fugitive code tells that it is achieving the same by reading the ssh config file to read information ('user', 'hostname' and 'port') which helps derive the remote url. |
hi @G0V1NDS , thanks for point that out, I will check |
@linrongbin16 the solution I implemented in a PR upstream parses the result I can open the same PR here if it makes sense. |
yeah, @joaodubas thank you! seems using ssh is the correct way to get the domain. at first I am only thinking I can use a regex thing (lua pattern) to map host to remote, but now I found it's much more complicated. a permanent git url contains multiple components ( for example: https://github.com/neovim/neovim/blob/2e156a3b7d7e25e56b03683cc6228c531f4c91ef/src/nvim/main.c#L137-L156):
I am thinking how to make this thing real powerful and customizable. |
@joaodubas , oh, I forgot why this lua/gitlinker/ssh.lua not in my fork (maybe at first I didn't know what this I will patch this part back to my fork. thanks for point that! |
@linrongbin16 this is the module I created to solve the issue with aliases in |
hi @joaodubas , @G0V1NDS , I'm trying to add But I have some issue when testing it in my local machine. I guess I don't have a correct environment (alias git host) to test this feature, would you please help test if it's working? Or if this feature could be tested without an alias git host environment, would you please help my testing steps (not sure if my steps have any issues):
|
@linrongbin16 your ssh and git config looks good to me. |
@linrongbin16 All the issues are resolved, thanks for quick update. Were you able to fix your local issue regarding |
No, I still failed to generate the git link in my local environment, but since you helped testing, I will merge into master branch now. really thanks to your contribute! |
solved |
Original issue in upstream repo: ruifm/gitlinker.nvim#53
Working PR for the same in upstream repo: ruifm/gitlinker.nvim#52 (Pending review)
The text was updated successfully, but these errors were encountered: