mirror of
https://github.com/boxpositron/absolute-vim.git
synced 2026-02-28 03:30:36 +00:00
feat(lua): add helper functions to open project folder based on OS for better navigation
This commit is contained in:
1
lua/absolute/helpers/init.lua
Normal file
1
lua/absolute/helpers/init.lua
Normal file
@@ -0,0 +1 @@
|
||||
require("absolute.helpers.open-project-folder")
|
||||
30
lua/absolute/helpers/open-project-folder.lua
Normal file
30
lua/absolute/helpers/open-project-folder.lua
Normal file
@@ -0,0 +1,30 @@
|
||||
local current_os = require("absolute.utils.detect-os")
|
||||
local get_git_root = require("absolute.utils.get-git-root")
|
||||
|
||||
local os_name = current_os.detect()
|
||||
local supported_os = current_os.supported
|
||||
|
||||
function Open_project_root()
|
||||
local project_root = get_git_root()
|
||||
|
||||
if os_name == supported_os.MACOS then
|
||||
vim.fn.jobstart("open " .. project_root, { detach = true })
|
||||
return
|
||||
end
|
||||
|
||||
if os_name == supported_os.UNIX then
|
||||
vim.fn.jobstart("xdg-open " .. project_root, { detach = true })
|
||||
return
|
||||
end
|
||||
|
||||
if os_name == supported_os.WINDOWS then
|
||||
vim.fn.jobstart("explorer " .. project_root, { detach = true })
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local opts = { noremap = true, silent = true }
|
||||
|
||||
opts.desc = "Open project root"
|
||||
|
||||
vim.api.nvim_set_keymap("n", "<leader>op", "<cmd>lua Open_project_root()<cr>", opts)
|
||||
Reference in New Issue
Block a user