Skip to content

Commit

Permalink
detect linux os (#29)
Browse files Browse the repository at this point in the history
* detect linux os and open via obsidan command on path

* use xdg-open to open obsidian uri

* Update lua/obsidian/command.lua

Co-authored-by: Pete <[email protected]>

* Small refactor

Co-authored-by: Pete <[email protected]>
  • Loading branch information
jmbuhr and epwalsh authored Oct 12, 2022
1 parent ff7123e commit d0d10bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
It's now more readable.
- Removed save on write for `:ObsidianNew` and `:ObsidianToday` ([#32](https://github.com/epwalsh/obsidian.nvim/pull/32)).

### Fixed

- `:ObsidianOpen` now works on Linux.

## [v1.4.0](https://github.com/epwalsh/obsidian.nvim/releases/tag/v1.4.0) - 2022-10-11

### Added
Expand Down
23 changes: 17 additions & 6 deletions lua/obsidian/command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,24 @@ command.open = function(client, data)

local encoded_vault = util.urlencode(vault_name)
local encoded_path = util.urlencode(tostring(path))

local app = "/Applications/Obsidian.app"
if Path:new(app):exists() then
local cmd = ("open -a %s --background 'obsidian://open?vault=%s&file=%s'"):format(app, encoded_vault, encoded_path)
os.execute(cmd)
local cmd = nil
local sysname = vim.loop.os_uname().sysname
if sysname == "Linux" then
cmd = ("xdg-open 'obsidian://open?vault=%s&file=%s'"):format(encoded_vault, encoded_path)
elseif sysname == "Darwin" then
cmd = ("open -a /Applications/Obsidian.app --background 'obsidian://open?vault=%s&file=%s'"):format(
encoded_vault,
encoded_path
)
else
echo.err "could not detect Obsidian application"
echo.err "open command does not support this OS yet"
end

if cmd ~= nil then
local return_code = os.execute(cmd)
if return_code > 0 then
echo.err "failed opening Obsidian app to note"
end
end
end

Expand Down

0 comments on commit d0d10bf

Please sign in to comment.