Skip to content

Commit

Permalink
refactor: use 0.10.0 vim.ui.open for opening url, falling back to cus…
Browse files Browse the repository at this point in the history
…tom defined open

refactor: use 0.10.0 vim.ui.open for opening url, falling back to custom defined open

- replaced `url_open_command` with `url_open_handler`

BREAKING CHANGE: `url_open_command` replaced with `url_open_handler`
  • Loading branch information
RZMNR committed Jun 9, 2024
1 parent e09181f commit 56bd79c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,19 @@ nnoremap <space>otk :Telescope terraform_doc full_name=hashicorp/kubernetes<cr>
### Configurable settings
| Keys | Description | Options |
|--------------------------|------------------------------------------------------------------|-------------------------------------|
| `url_open_command` | The shell command to open the url | string (default: `open`/`xdg-open`) |
| `url_open_handler` | A function that will be used to open the url | function |
| `latest_provider_symbol` | The symbol for indicating that the current version is the latest | string (default: `*`) |
| `wincmd` | Command to open documentation in a split window | string (default: `botright vnew`) |
| `wrap` | Wrap lines in a documentation in a split window | string (default: `nowrap`) |

```lua
local function customOpen(url)
vim.fn.system('open -a Safari "' .. url .. '"')
end
require("telescope").setup({
extensions = {
terraform_doc = {
url_open_command = vim.fn.has("macunix") and "open" or "xdg-open",
url_open_handler = customOpen,
latest_provider_symbol = "",
wincmd = "botright vnew",
wrap = "nowrap",
Expand All @@ -88,5 +91,5 @@ require("telescope").setup({

| key | Usage |
|---------|--------------------------------------------|
| `<cr>` | Open documentation with `url_open_command` |
| `<cr>` | Open documentation with `url_open_handler` |
| `<c-d>` | Open documentation in a split window |
4 changes: 2 additions & 2 deletions lua/telescope/_extensions/terraform_doc/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function M.url_opener(opts)
actions.close(prompt_bufnr)

local url = M_api.get_docs_url(opts.full_name, opts.version, selection.category, selection.slug)
os.execute(string.format('%s "%s"', opts.url_open_command, url))
opts.url_open_handler(url)
end
end

Expand Down Expand Up @@ -41,7 +41,7 @@ function M.url_opener_module(opts)
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
local url = M_api.get_docs_url_module(selection.full_name, selection.provider_name)
os.execute(string.format('%s "%s"', opts.url_open_command, url))
opts.url_open_handler(url)
end
end

Expand Down
13 changes: 11 additions & 2 deletions lua/telescope/_extensions/terraform_doc/config.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
local M = {
opts = {
url_open_command = vim.fn.has("macunix") and "open" or "xdg-open",
latest_provider_symbol = "*",
version = "latest",
wincmd = "botright vnew",
wrap = "nowrap",
},
}

local function open(url)
if vim.fn.has("mac") == 1 then
vim.fn.system('open "' .. url .. '"')
elseif vim.fn.has("unix") == 1 then
vim.fn.system('xdg-open "' .. url .. '"')
elseif vim.fn.has("win32") == 1 or vim.fn.has("win64") == 1 then
vim.fn.system('start "" "' .. url .. '"')
end
end

M.setup = function(opts)
M.opts.url_open_command = opts.url_open_command or M.opts.url_open_command
M.opts.url_open_handler = opts.url_open_handler or vim.ui.open or open
M.opts.latest_provider_symbol = opts.latest_provider_symbol or M.opts.latest_provider_symbol
M.opts.wincmd = opts.wincmd or M.opts.wincmd
M.opts.wrap = opts.wrap or M.opts.wrap
Expand Down

0 comments on commit 56bd79c

Please sign in to comment.