Community
    • Login

    How to open local git file in remote git in browser?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 2 Posters 1.4k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • batagyB
      batagy
      last edited by batagy

      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#L12

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

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @batagy
        last edited by

        @batagy

        I’d suggest scripting.
        It sounds a bit much for NppExec, but, maybe, if you’re ambitious.

        1 Reply Last reply Reply Quote 0
        • batagyB
          batagy
          last edited by

          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-url

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

          1 Reply Last reply Reply Quote 1
          • batagyB
            batagy
            last edited by batagy

            Okey, now I made it to work.

            Solution:

            1. 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.
            2. Install NppExec plugin to Notepad++
            3. 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)"
            
            1. 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.

            :)

            1 Reply Last reply Reply Quote 2
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors