Closed ahakanbaba closed 5 years ago
Unfortunately your solution doesn't seem to work on my system with neither GNU nor BSD sed (I expect that the :
should be turned to /
):
bash-3.2$ echo git@github.com:ruanyl/vim-gh-line.git | gsed 's/(https)\@<!:/\//'
git@github.com:ruanyl/vim-gh-line.git
bash-3.2$ echo git@github.com:ruanyl/vim-gh-line.git | sed 's/(https)\@<!:/\//'
git@github.com:ruanyl/vim-gh-line.git
bash-3.2$ echo git@github.com:ruanyl/vim-gh-line.git | gsed 's/\(https\)\@<!:/\//'
git@github.com:ruanyl/vim-gh-line.git
bash-3.2$ echo git@github.com:ruanyl/vim-gh-line.git | sed 's/\(https\)\@<!:/\//'
git@github.com:ruanyl/vim-gh-line.git
Maybe I'm doing the shell/sed escapes wrong? Could you give any reference to the syntax of the negative lookbehind expression for sed that you're using? I couldn't find any.
However, it's possible to avoid lookbehinds completely for this problem by combining 1st and 2nd substitutions:
bash-3.2$ echo git@github.com:ruanyl/vim-gh-line.git | gsed 's/^[^@:]*@\([^:]*\):/https:\/\/\1\//'
https://github.com/ruanyl/vim-gh-line.git
bash-3.2$ echo git@github.com:ruanyl/vim-gh-line.git | sed 's/^[^@:]*@\([^:]*\):/https:\/\/\1\//'
https://github.com/ruanyl/vim-gh-line.git
bash-3.2$ echo https://github.com/ruanyl/vim-gh-line.git | sed 's/^[^@:]*@\([^:]*\):/https:\/\/\1\//'
https://github.com/ruanyl/vim-gh-line.git
bash-3.2$ echo https://github.com/ruanyl/vim-gh-line.git | gsed 's/^[^@:]*@\([^:]*\):/https:\/\/\1\//'
https://github.com/ruanyl/vim-gh-line.git
PS: It would be nice to set up regression tests and CI for this project (obviously not in this PR, but in general).
Thank you @KostyaEsmukov for your input. I have used the regular expressions you suggested. The need for forward-backward slash escaping is rather unfortunate but I think this should work. It did in my setup.
@ahakanbaba Thanks! I think that will do.
@ruanyl could you please review this PR ? It is a bugfix and it would be good to merge it sooner than later.
thank you very much for the pr, works good with Github/Bitbucket https and ssh remote url.
fixes #16