Skip to content

Commit 64de405

Browse files
authored
fix(open): linux error spawning new obsidian process (#346)
* fix(open): use luv to spawn obsidian app * refactor: use jobstart for backwards compatibility * refactor(open): add error logging to jobstart * chore(open): change log message for consistent formatting * chore(open): include shell command when logging error * chore(open): reduce diff * chore(open): last cleanup
1 parent b101ad8 commit 64de405

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lua/obsidian/commands/open.lua

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
local util = require "obsidian.util"
22
local log = require "obsidian.log"
33
local RefTypes = require("obsidian.search").RefTypes
4-
local run_job = require("obsidian.async").run_job
54

65
---@param client obsidian.Client
76
return function(client, data)
@@ -56,6 +55,8 @@ return function(client, data)
5655
uri = ("obsidian://open?vault=%s&file=%s"):format(encoded_vault, encoded_path)
5756
end
5857

58+
uri = vim.fn.shellescape(uri)
59+
5960
---@type string, string[]
6061
local cmd, args
6162
if this_os == util.OSType.Linux then
@@ -81,5 +82,14 @@ return function(client, data)
8182

8283
assert(cmd)
8384
assert(args)
84-
run_job(cmd, args)
85+
86+
local cmd_with_args = cmd .. " " .. table.concat(args, " ")
87+
vim.fn.jobstart(cmd_with_args, {
88+
detach = true,
89+
on_exit = function(_, exit_code)
90+
if exit_code ~= 0 then
91+
log.err("open command failed with exit code '%s': %s", exit_code, cmd_with_args)
92+
end
93+
end,
94+
})
8595
end

0 commit comments

Comments
 (0)