Skip to content

Commit

Permalink
feat(skim): added __SK_VERSION variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Nov 27, 2024
1 parent ce97847 commit e2f7165
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lua/fzf-lua/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,14 @@ function M.normalize_opts(opts, globals, __resume_key)
opts.fzf_opts = opts.fzf_opts or {}
opts.fzf_opts["--border"] = false
end
else
local SK_VERSION, rc, err = utils.sk_version(opts)
opts.__SK_VERSION = SK_VERSION
if not opts.__SK_VERSION then
utils.err(string.format(
"'sk --version' failed with error %s: %s", rc, err))
return nil
end
end

if opts.__FZF_VERSION and opts.__FZF_VERSION >= 0.53
Expand Down
24 changes: 20 additions & 4 deletions lua/fzf-lua/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1177,16 +1177,31 @@ function M.neovim_bind_to_fzf(key)
return key
end

local function version_str_to_num(str)
if type(str) ~= "string" then return end
local major, minor, patch = str:match("(%d+).(%d+).(%d+)")
if not major and str:match("HEAD") then return 5 end
return tonumber(string.format("%d.%d%d", major, minor, patch))
end

function M.fzf_version(opts)
opts = opts or {}
-- temp unset "FZF_DEFAULT_OPTS" as it might fail `--version`
-- if it contains options aren't compatible with fzf's version
local FZF_DEFAULT_OPTS = vim.env.FZF_DEFAULT_OPTS
vim.env.FZF_DEFAULT_OPTS = nil
local out, rc = M.io_system({ opts.fzf_bin or "fzf", "--version" })
vim.env.FZF_DEFAULT_OPTS = FZF_DEFAULT_OPTS
if out:match("HEAD") then return 4 end
return tonumber(out:match("(%d+.%d+).")), rc, out
return version_str_to_num(out), rc, out
end

function M.sk_version(opts)
-- temp unset "SKIM_DEFAULT_OPTIONS" as it might fail `--version`
-- if it contains options aren't compatible with sk's version
local SKIM_DEFAULT_OPTIONS = vim.env.SKIM_DEFAULT_OPTIONS
vim.env.SKIM_DEFAULT_OPTIONS = nil
local out, rc = M.io_system({ opts.fzf_bin or "sk", "--version" })
vim.env.SKIM_DEFAULT_OPTIONS = SKIM_DEFAULT_OPTIONS
return version_str_to_num(out), rc, out
end

function M.git_version()
Expand Down Expand Up @@ -1256,7 +1271,8 @@ end
---@return boolean
function M.jump_to_location(location, offset_encoding, reuse_win)
if M.__HAS_NVIM_011 then
return vim.lsp.util.show_document(location, offset_encoding, { reuse_win = reuse_win, focus = true })
return vim.lsp.util.show_document(location, offset_encoding,
{ reuse_win = reuse_win, focus = true })
else
return vim.lsp.util.jump_to_location(location, offset_encoding, reuse_win)
end
Expand Down

0 comments on commit e2f7165

Please sign in to comment.