Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance open_online action #25

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions lua/telescope/_extensions/packer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ local setup = function(opts)
end
end

local function opener()
local sysname = vim.loop.os_uname().sysname
if sysname == "Darwin" then
return 'open'
elseif sysname == "Windows" then
return "explorer"
elseif vim.fn.executable("wslview") then
return 'wslview'
elseif vim.fn.executable("xdg-open") then
return 'xdg-open'
else
return nil
end
end

local function get_url(path)
local url = vim.fn.trim(vim.fn.system(string.format("git -C %s ls-remote --get-url", path)))
if string.sub(url, 1, 6) == 'ssh://' then
url, _ = string.gsub(url, '^ssh://%w+@', 'https://')
url, _ = string.gsub(url, '^ssh://', 'https://')
end
Comment on lines +50 to +53
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh one more thing it could also start with [email protected]:nvim-telescope/telescope.nvim.git e.g.

return url
end

local plugins = function(opts)
opts = vim.tbl_deep_extend("force", user_opts, opts or {})

Expand Down Expand Up @@ -89,8 +113,12 @@ local plugins = function(opts)
local selection = action_state.get_selected_entry()
actions._close(prompt_bufnr)

local cmd = vim.fn.has "win32" == 1 and "explorer" or vim.fn.has "mac" == 1 and "open" or "xdg-open"
local url = vim.fn.trim(vim.fn.system(string.format("git -C %s ls-remote --get-url", selection.path)))
local cmd = opener()
if cmd == nil then
vim.notify("No executables to open file/url", vim.log.levels.ERROR)
return
end
local url = get_url(selection.path)
Job:new({command = cmd, args = {url}}):start()
end

Expand Down