From 38983228c83dcdf267a06be8b9174e233a082c76 Mon Sep 17 00:00:00 2001 From: rxi Date: Tue, 12 May 2020 21:08:02 +0100 Subject: Added `openselected` and `openfilelocation` --- plugins/openfilelocation.lua | 28 ++++++++++++++++++++++++++++ plugins/openselected.lua | 26 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 plugins/openfilelocation.lua create mode 100644 plugins/openselected.lua (limited to 'plugins') diff --git a/plugins/openfilelocation.lua b/plugins/openfilelocation.lua new file mode 100644 index 0000000..e57b740 --- /dev/null +++ b/plugins/openfilelocation.lua @@ -0,0 +1,28 @@ +local core = require "core" +local command = require "core.command" +local config = require "core.config" + + +if PLATFORM == "Windows" then + config.filemanager = "explorer" +else + config.filemanager = "xdg-open" +end + + +command.add("core.docview", { + ["open-file-location:open-file-location"] = function() + local doc = core.active_view.doc + if not doc.filename then + core.error "Cannot open location of unsaved doc" + return + end + local folder_name = doc.filename:match("^(.-)[^/\\]*$") + core.log("Opening \"%s\"", folder_name) + if PLATFORM == "Windows" then + os.execute(string.format("start %s %s", config.filemanager, folder_name)) + else + os.execute(string.format("%s %q", config.filemanager, folder_name)) + end + end +}) diff --git a/plugins/openselected.lua b/plugins/openselected.lua new file mode 100644 index 0000000..5fadbec --- /dev/null +++ b/plugins/openselected.lua @@ -0,0 +1,26 @@ +local core = require "core" +local command = require "core.command" +local keymap = require "core.keymap" + + +command.add("core.docview", { + ["open-selected:open-selected"] = function() + local doc = core.active_view.doc + if not doc:has_selection() then + core.error("No text selected") + return + end + + local text = doc:get_text(doc:get_selection()) + core.log("Opening \"%s\"...", text) + + if PLATFORM == "Windows" then + os.execute(string.format("start explorer %s", text)) + else + os.execute(string.format("xdg-open %q &", text)) + end + end, +}) + + +keymap.add { ["ctrl+shift+o"] = "open-selected:open-selected" } -- cgit v1.2.3