aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Minor <github@pixelverse.org>2021-11-18 23:05:33 -0800
committerJoshua Minor <github@pixelverse.org>2021-11-18 23:05:33 -0800
commit5014da1b7bcf4be0cb6e394da8f968c78334cf7a (patch)
treef5f80b56bd46dede6618df1679443f6c381ee802
parentbc0a289a79294445de9b0001bdaada93d801dadd (diff)
downloadlite-xl-plugins-5014da1b7bcf4be0cb6e394da8f968c78334cf7a.tar.gz
lite-xl-plugins-5014da1b7bcf4be0cb6e394da8f968c78334cf7a.zip
Fixed openselected so it works on macOS.
Trim whitespace from ends of selected text. Quote the selected text before sending to the shell, in case there are spaces, quotes, etc.
-rw-r--r--plugins/openselected.lua27
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" }
+