Sublime Forum

GitURLToClipboard

#1

I haven’t found a pluggin to open my gitlab projects directly (access to the pipeline, etc…).

That’s why I used the Build system function for my needs.

While it may be useful to others, I take the liberty of sharing here.

Maybe there are ways of doing this that I didn’t know about.


1. Create a PowerShell script :

C:\PATH\TO\SCRIPT\git_url_to_clipboard.ps1

# Retrieve the URL from the git repository and convert it to HTTPS
$url = git config --get remote.origin.url
$httpsUrl = $url -replace 'git@([^:]*):(.*).git', 'https://$1/$2'

# Copy the transformed URL to the clipboard
$httpsUrl | Set-Clipboard

# Open the URL in the default browser
Start-Process $httpsUrl

2. Create a Build System :

Tools > Build System > New Build System...

GitURLToClipboard.sublime-build

{
    "cmd": ["powershell", "-ExecutionPolicy", "Bypass", "-File", "C:\\PATH\\TO\\SCRIPT\\git_url_to_clipboard.ps1"],
    "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
    "working_dir": "$file_path",
    "selector": "source.shell"
}

3. Usage

  • Select : Tools > Build System > GitURLToClipboard
  • Press : Ctrl + B on any open file !
0 Likes

#2

I have it in my personal plugin.
image

Specifically, it’s implemented in https://github.com/jfcherng-sublime/ST-CommandAndMenu/blob/1880be345bcd456d0df786888dc02d2d3afa6d3c/plugin/commands/open_git_repo_on_web.py

1 Like

#3

wow I will see how it’s working (I’m a fresh ST user)

0 Likes