aboutsummaryrefslogtreecommitdiff
path: root/plugins/openfilelocation.lua
blob: e57b7406ebf5428065a3898a28b1ea485c6313f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
})