Skip to content

Commit c4427eb

Browse files
committed
OS detection so links can be clicked in obsidian nvim
1 parent 349545b commit c4427eb

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

init.lua

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
-- Set <space> as the leader key
22
-- See `:help mapleader`
33
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
4+
5+
if vim.fn.exists 'g:os' == 0 then
6+
local is_windows = vim.fn.has 'win64' == 1 or vim.fn.has 'win32' == 1 or vim.fn.has 'win16' == 1
7+
if is_windows then
8+
vim.g.os = 'Windows'
9+
else
10+
local uname_output = vim.fn.system 'uname'
11+
vim.g.os = string.gsub(uname_output, '\n', '')
12+
end
13+
end
14+
415
vim.g.mapleader = ' '
516
vim.g.maplocalleader = ' '
617

@@ -452,7 +463,7 @@ require('lazy').setup({
452463
-- Where to put new notes. Valid options are
453464
-- * "current_dir" - put new notes in same directory as the current buffer.
454465
-- * "notes_subdir" - put new notes in the default notes subdirectory.
455-
new_notes_location = 'notes_subdir',
466+
new_notes_location = 'current_dir',
456467

457468
-- Optional, customize how note IDs are generated given an optional title.
458469
---@param title string|?
@@ -540,9 +551,13 @@ require('lazy').setup({
540551
---@param url string
541552
follow_url_func = function(url)
542553
-- Open the URL in the default web browser.
543-
vim.fn.jobstart { 'open', url } -- Mac OS
554+
555+
if vim.g.os == 'Windows' then
556+
vim.cmd(':silent exec "!start ' .. url .. '"') -- Windows
557+
else
558+
vim.fn.jobstart { 'open', url } -- Mac OS
559+
end
544560
-- vim.fn.jobstart({"xdg-open", url}) -- linux
545-
-- vim.cmd(':silent exec "!start ' .. url .. '"') -- Windows
546561
-- vim.ui.open(url) -- need Neovim 0.10.0+
547562
end,
548563

0 commit comments

Comments
 (0)