sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

support url handlers to open files from url

Open a7madgamal opened this issue 6 years ago • 9 comments
trafficstars

Problem description

basically, support this nativly https://github.com/inopinatus/sublime_url why? because I made this https://github.com/a7madgamal/open_github_in_editor and I would love to add your amazing editor to the list of supported editors :D

I'm more interested in MacOs support but other OS are welcome I guess

Preferred solution

just adjust the installers to add the url handler

a7madgamal avatar Dec 10 '18 01:12 a7madgamal

still no updates? :(

a7madgamal avatar Aug 23 '20 20:08 a7madgamal

What kind of problems does a custom scheme solve?

rwols avatar Aug 23 '20 20:08 rwols

I need a way to open a specific file and line number using a url-like format as I use for vscode and other editors

a7madgamal avatar Aug 23 '20 22:08 a7madgamal

But do you need a custom scheme for this? Why can’t you use the over-arching script and/or environment to select the appropriate program? The subl executable already supports file:line:col syntax so I don’t see any problems with this. And if you’re choosing subl:// as the scheme then you’ve already iterated over the possible editors in your over-arching script I would think.

rwols avatar Aug 23 '20 22:08 rwols

not sure what you mean by over-arching script but since my addon runs only in a browser I only have access to links not executables. if 'subl://filepath.ext:lineNumber' works then we have no issues here 😁 this is what we need exactly https://github.com/microsoft/vscode/issues/4883

On Mon, Aug 24, 2020, 12:53 AM Raoul Wols [email protected] wrote:

But do you need a custom scheme for this? Why can’t you use the over-arching script and/or environment to select the appropriate program? The subl executable already supports file:line:col syntax so I don’t see any problems with this. And if you’re choosing subl:// as the scheme then you’ve already iterated over the possible editors in your over-arching script I would think.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sublimehq/sublime_text/issues/2514#issuecomment-678835235, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHFMUWSTWJFHAWNJXEBWSLSCGMWNANCNFSM4GJJ4Q6Q .

a7madgamal avatar Aug 23 '20 23:08 a7madgamal

@rwols sorry I didn't get your answer. any updates on this topic since then?

a7madgamal avatar Nov 21 '22 11:11 a7madgamal

An extension to this request is to support web links to clone a git repo directly into the editor as a new project. VS Code supports such a scheme:

vscode://vscode.git/clone?url=https://github.com/sublimehq/sublime_text

The url parameter should be url-encoded, I only decoded it for demonstrative purpose.

silverwind avatar Mar 06 '24 20:03 silverwind

I was able to register subl as a protocol handler, but I couldn't get it to actually open a file, it opens c:/windows/system32/subl instead :/

titoBouzout avatar Apr 20 '24 08:04 titoBouzout

I figured it out for windows

; sublime text protocol

[HKEY_CLASSES_ROOT\subl]
"URL Protocol"=""
[HKEY_CLASSES_ROOT\subl\shell\open\command]
@="\"D:\\Software\\portable\\Sublime Text\\sublime_text.exe\" --command \"open_file_from_url {\\\"url\\\": \\\"%1\\\"}\""

; pretend we are vscode

[HKEY_CLASSES_ROOT\vscode]
"URL Protocol"=""
[HKEY_CLASSES_ROOT\vscode\shell\open\command]
@="\"D:\\Software\\portable\\Sublime Text\\sublime_text.exe\" --command \"open_file_from_url {\\\"url\\\": \\\"%1\\\"}\""

then in the user folder add this command

import sublime_plugin
import sublime
import re

from urllib.parse import unquote


class OpenFileFromUrlCommand(sublime_plugin.WindowCommand):
    def run(self, url):

        url = unquote(re.sub(r"^(vscode|subl):(\/\/)?((file|open)\/)?", "", url))

        self.window.open_file(url, sublime.ENCODED_POSITION)


titoBouzout avatar Apr 23 '24 05:04 titoBouzout