refactor(nvim): use xdg-open & vim.system for Search function

This commit is contained in:
Price Hiller 2023-09-06 15:24:16 -05:00
parent a37abf1c17
commit e01700dab6
No known key found for this signature in database

View File

@ -168,18 +168,18 @@ return {
results = { results = {
{ {
"Stack Overflow", "Stack Overflow",
("www.stackoverflow.com/search\\?q\\=" .. search:gsub(" ", "+")), ("https://www.stackoverflow.com/search?q=" .. search:gsub(" ", "+")),
}, },
{ "Google Search", ("www.google.com/search\\?q\\=" .. search:gsub(" ", "+")) }, { "Google Search", ("www.google.com/search?q=" .. search:gsub(" ", "+")) },
{ {
"Youtube", "Youtube",
("https://www.youtube.com/results\\?search_query\\=" .. search:gsub(" ", "+")), ("https://www.youtube.com/results?search_query=" .. search:gsub(" ", "+")),
}, },
{ {
"Wikipedia", "Wikipedia",
("https://en.wikipedia.org/w/index.php\\?search\\=" .. search:gsub(" ", "+")), ("https://en.wikipedia.org/w/index.php?search=" .. search:gsub(" ", "+")),
}, },
{ "Github", ("https://github.com/search\\?q\\=" .. search:gsub(" ", "+")) }, { "Github", ("https://github.com/search?q=" .. search:gsub(" ", "+")) },
}, },
entry_maker = function(entry) entry_maker = function(entry)
return { value = entry, display = entry[1], ordinal = entry[1] } return { value = entry, display = entry[1], ordinal = entry[1] }
@ -190,11 +190,14 @@ return {
actions.select_default:replace(function() actions.select_default:replace(function()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry() local selection = action_state.get_selected_entry()
vim.cmd( ---@param obj vim.SystemCompleted
("silent execute '!firefox-developer-edition %s &'"):format( vim.system({ "xdg-open", selection["value"][2] }, { text = true }, function(obj)
selection["value"][2] if obj.code ~= 0 then
) vim.notify(string.format(
) "Failed to open selection, exit code: %s!\n---Stdout---\n%s\n---Stderr---\n%s",
obj.code, obj.stdout, obj.stderr))
end
end)
end) end)
return true return true
end, end,