From c4427eb003b54e20c1814c1c9b5e18e20287a8c9 Mon Sep 17 00:00:00 2001 From: Sayed Abdulmohsen Alhashemi Date: Sun, 30 Mar 2025 12:39:01 +0300 Subject: [PATCH] OS detection so links can be clicked in obsidian nvim --- init.lua | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index 79500a87..5a0ea200 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,17 @@ -- Set as the leader key -- See `:help mapleader` -- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) + +if vim.fn.exists 'g:os' == 0 then + local is_windows = vim.fn.has 'win64' == 1 or vim.fn.has 'win32' == 1 or vim.fn.has 'win16' == 1 + if is_windows then + vim.g.os = 'Windows' + else + local uname_output = vim.fn.system 'uname' + vim.g.os = string.gsub(uname_output, '\n', '') + end +end + vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' @@ -452,7 +463,7 @@ require('lazy').setup({ -- Where to put new notes. Valid options are -- * "current_dir" - put new notes in same directory as the current buffer. -- * "notes_subdir" - put new notes in the default notes subdirectory. - new_notes_location = 'notes_subdir', + new_notes_location = 'current_dir', -- Optional, customize how note IDs are generated given an optional title. ---@param title string|? @@ -540,9 +551,13 @@ require('lazy').setup({ ---@param url string follow_url_func = function(url) -- Open the URL in the default web browser. - vim.fn.jobstart { 'open', url } -- Mac OS + + if vim.g.os == 'Windows' then + vim.cmd(':silent exec "!start ' .. url .. '"') -- Windows + else + vim.fn.jobstart { 'open', url } -- Mac OS + end -- vim.fn.jobstart({"xdg-open", url}) -- linux - -- vim.cmd(':silent exec "!start ' .. url .. '"') -- Windows -- vim.ui.open(url) -- need Neovim 0.10.0+ end,