How to open local git file in remote git in browser?
-
Hi,
Let’s suppose I cloned a git repo locally, and working in that with Notepad++.
But, sometime I want to jump from a particular line (in a local file) to the same line in the remote git repo in a browser.In other words, from Notepad++ I want to open an URL such this example:
https://gitlab-central.somecompany.com/path1/repo/-/blob/master/path2/code.yml#L12The parts in URL comes from
-
The FQDN and first path possible could come from ‘git config --get remote.origin.url’
-
“blob/master” is the current branch, ideally this could come from ‘git branch --show-current’ but if this is fixed “blob/master” string then it’s also useful.
-
Second path inside the repo should be detected somehow.
-
Ideally, the current line number should be detected and passed in URL to the browser. This last one is preferred but not mandatory.
How can we do this?
Maybe with NppExec plugin somehow?Thanks in advance!
-
-
I’d suggest scripting.
It sounds a bit much for NppExec, but, maybe, if you’re ambitious. -
Hi,
I found maybe a solution for the first part of the problem.
This small git companion bash script can be used to print the full path (with FQDN , branch and path to file) to git repo as an URL:
git-urlInstallation is in the readme.
It seems this runs also from Windows prompt (probably because I have git /bash installed, but maybe due to WSL enabled)So, we should run command “git url currentfile.yml” and just open this is a predefined browser,
Also, if we detect the current line number in Notepad++, then that string should be added to end of path as “#L12”.Can this be done?
-
Okey, now I made it to work.
Solution:
- Install git-url helper script, according to the readme in that.
This is a bash script but runs also on Windows if Git Bash installed. - Install NppExec plugin to Notepad++
- Use below NppExec script , save it to a name like “OpenGitInBrowser”
NPP_CONSOLE 0 NPE_CONSOLE v+ cd "$(CURRENT_DIRECTORY)" git url "$(FILE_NAME)" npp_run firefox "$(OUTPUT)#L$(CURRENT_LINE)"
- If you view or edit a file in git repo in Notepad++, press F6, select the above script, and done.
It will jump to the actual line number in browser, in the given branch. This URL format is compatible with gitlab. Didn’t test with other git repo services,
It runs hidden (no console opening for NppExec), and it takes some seconds because of bash script, bit working fine.
:)
- Install git-url helper script, according to the readme in that.