feat(api): add get_current_url() for adapter-agnostic URL access (#119)
Problem: `get_current_dir()` returns nil for non-local adapters (SSH, S3, trash), leaving users with no public API to get the current buffer's location. Solution: add `get_current_url()` which returns the full canola URL for any adapter, or nil if not in a canola buffer. Based on: stevearc/oil.nvim#646
This commit is contained in:
parent
9d29243faf
commit
9298b48c5d
3 changed files with 25 additions and 2 deletions
|
|
@ -154,6 +154,19 @@ M.get_current_dir = function(bufnr)
|
|||
end
|
||||
end
|
||||
|
||||
---Get the current buffer's canola URL (e.g. "canola:///path/" or "canola-ssh://host/path/")
|
||||
---@param bufnr? integer
|
||||
---@return nil|string
|
||||
M.get_current_url = function(bufnr)
|
||||
local config = require('canola.config')
|
||||
local util = require('canola.util')
|
||||
local buf_name = vim.api.nvim_buf_get_name(bufnr or 0)
|
||||
local scheme = util.parse_url(buf_name)
|
||||
if scheme and config.adapters[scheme] then
|
||||
return buf_name
|
||||
end
|
||||
end
|
||||
|
||||
---Get the canola url for a given directory
|
||||
---@private
|
||||
---@param dir nil|string When nil, use the cwd
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue