module Editor
Maps editor names to URL schemes for opening files.
Checks the EDITOR environment variable and generates clickable URLs
for known editors. Returns nil for unknown editors.
Definitions
def self.url_for(path, line = 1)
Generate a URL for opening a file in the current editor.
Signature
-
parameter
pathString The file path to open.
-
parameter
lineInteger The line number (1-based).
-
returns
String | Nil The editor URL, or
nilif the editor is unknown.
Implementation
def self.url_for(path, line = 1)
editor = ENV["PRESENTLY_EDITOR"] || ENV["EDITOR"]
return nil unless editor
# Extract the editor name from the path (e.g. "/usr/bin/code" -> "code")
name = File.basename(editor).split(/\s+/).first
if pattern = EDITORS[name]
sprintf(pattern, File.expand_path(path), line)
end
end