diff options
author | cukmekerb <cukmekerb@gmail.com> | 2021-11-26 21:42:50 -0800 |
---|---|---|
committer | cukmekerb <cukmekerb@gmail.com> | 2021-11-26 21:42:50 -0800 |
commit | 3834db399042ac72c032d94b510cf5921e123b3a (patch) | |
tree | 25c541b00d8db5c1b5976b052e2cdad0a8eb8473 /plugins/openselected.lua | |
parent | c75f20b1eeac107bfbe3ba38f515cdf0c445dc61 (diff) | |
parent | 5014da1b7bcf4be0cb6e394da8f968c78334cf7a (diff) | |
download | lite-xl-plugins-3834db399042ac72c032d94b510cf5921e123b3a.tar.gz lite-xl-plugins-3834db399042ac72c032d94b510cf5921e123b3a.zip |
Merge branch 'fix_openselected' of https://github.com/jminor/lite-plugins
Diffstat (limited to 'plugins/openselected.lua')
-rw-r--r-- | plugins/openselected.lua | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/plugins/openselected.lua b/plugins/openselected.lua index a1e21a2..af00194 100644 --- a/plugins/openselected.lua +++ b/plugins/openselected.lua @@ -2,6 +2,17 @@ local core = require "core" local command = require "core.command" local keymap = require "core.keymap" +local config = require "core.config" + + +config.plugins.openselected = {} +if PLATFORM == "Windows" then + config.plugins.openselected.filemanager = "start" +elseif PLATFORM == "Mac OS X" then + config.plugins.openselected.filemanager = "open" +else + config.plugins.openselected.filemanager = "xdg-open" +end command.add("core.docview", { @@ -13,15 +24,21 @@ command.add("core.docview", { end local text = doc:get_text(doc:get_selection()) - core.log("Opening \"%s\"...", text) - if PLATFORM == "Windows" then - system.exec("start " .. text) - else - system.exec(string.format("xdg-open %q", text)) + -- trim whitespace from the ends + text = text:match( "^%s*(.-)%s*$" ) + + -- non-Windows platforms need the text quoted (%q) + if PLATFORM ~= "Windows" then + text = string.format("%q", text) end + + core.log("Opening %s...", text) + + system.exec(config.plugins.openselected.filemanager .. " " .. text) end, }) keymap.add { ["ctrl+shift+o"] = "open-selected:open-selected" } + |