Skip to content

Commit

Permalink
refactor: generating shell wrapper command / env vars
Browse files Browse the repository at this point in the history
refactor: retire complex windows escaping logic
refactor: fzf `--multi` option
refactor: path module (+added tests)
fix: misc fixes for windows
fix: cwd header test
fix: path.starts_with_separator
fix: git commits|bcommits
fix: git_diff previewer `sh -c` -> `cmd`
fix: profiles, help_tags
chore: lua_ls warnings, format luarc.json with prettier
feat: added support for listing files with `dir /s/b/a:-d`
fix: path shorten/lengthen
fix(make_entry): cwd_only check
fix(path.shorten): do not shorten drive spec
fix(paths): `HOME_to_tilde` case insensitive on windows
fix(live_grep): with `exec_empty_query={true|false}`
refactor(core): multiprocess cmd args serialization (WIP)
fix(live_grep): special chars (WIP)
  • Loading branch information
ibhagwan committed Jan 28, 2024
1 parent 4b1d6f1 commit d39677f
Show file tree
Hide file tree
Showing 37 changed files with 1,569 additions and 567 deletions.
25 changes: 7 additions & 18 deletions .luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,24 @@
"runtime.version": "LuaJIT",
"diagnostics": {
"enable": true,
"globals": [
"vim",
"describe",
"pending",
"it",
"before_each",
"after_each"
],
"globals": ["vim"],
"neededFileStatus": {
"codestyle-check": "Any"
},
"disable": [
"need-check-nil",
"missing-parameter",
"cast-local-type"
]
"disable": ["need-check-nil", "missing-parameter", "cast-local-type"]
},
"workspace": {
"library": [
"$VIMRUNTIME/lua",
"lua",
"${3rd}/luv/library"
"$VIMRUNTIME/lua",
"${3rd}/luv/library",
"$XDG_DATA_HOME/nvim/lazy/plenary.nvim/lua",
"$LOCALAPPDATA/nvim-data/lazy/plenary.nvim/lua"
],
"checkThirdParty": false,
"maxPreload": 2000,
"preloadFileSize": 1000,
"ignoreDir": [
"tests/"
]
"ignoreDir": ["tests/"]
},
"type": {
"weakNilCheck": true,
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,6 @@ require'fzf-lua'.setup {
.. " %(subject) %(color:blue)%(taggername)%(color:reset)' refs/tags",
preview = "git log --graph --color --pretty=format:'%C(yellow)%h%Creset "
.. "%Cgreen(%><(12)%cr%><|(12))%Creset %s %C(blue)<%an>%Creset' {1}",
fzf_opts = { ["--no-multi"] = "" },
actions = { ["default"] = actions.git_checkout },
},
stash = {
Expand All @@ -888,10 +887,6 @@ require'fzf-lua'.setup {
["default"] = actions.git_stash_apply,
["ctrl-x"] = { fn = actions.git_stash_drop, reload = true },
},
fzf_opts = {
["--no-multi"] = '',
['--delimiter'] = "'[:]'",
},
},
icons = {
["M"] = { icon = "M", color = "yellow" },
Expand Down
7 changes: 1 addition & 6 deletions doc/fzf-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,6 @@ open an issue and I'll be more than happy to help.**
.. " %(subject) %(color:blue)%(taggername)%(color:reset)' refs/tags",
preview = "git log --graph --color --pretty=format:'%C(yellow)%h%Creset "
.. "%Cgreen(%><(12)%cr%><|(12))%Creset %s %C(blue)<%an>%Creset' {1}",
fzf_opts = { ["--no-multi"] = "" },
actions = { ["default"] = actions.git_checkout },
},
stash = {
Expand All @@ -981,10 +980,6 @@ open an issue and I'll be more than happy to help.**
["default"] = actions.git_stash_apply,
["ctrl-x"] = { fn = actions.git_stash_drop, reload = true },
},
fzf_opts = {
["--no-multi"] = '',
['--delimiter'] = "'[:]'",
},
},
icons = {
["M"] = { icon = "M", color = "yellow" },
Expand Down Expand Up @@ -1438,4 +1433,4 @@ I missed your name feel free to contact me and I'll add it below:
as baseline for the builtin previewer and his must have plugin nvim-bqf
<https://github.com/kevinhwang91/nvim-bqf>

vim:tw=78:ts=8:ft=help:norl:
vim:tw=78:ts=8:ft=help:norl:
18 changes: 10 additions & 8 deletions lua/fzf-lua/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ M.expect = function(actions)
end
end
if #keys > 0 then
return string.format("--expect=%s", table.concat(keys, ","))
return table.concat(keys, ",")
end
return nil
end
Expand Down Expand Up @@ -104,7 +104,7 @@ M.vimcmd_file = function(vimcmd, selected, opts)
if entry.path == "<none>" then goto continue end
entry.ctag = opts._ctag and path.entry_to_ctag(selected[i])
local fullpath = entry.path or entry.uri and entry.uri:match("^%a+://(.*)")
if not path.starts_with_separator(fullpath) then
if not path.is_absolute(fullpath) then
fullpath = path.join({ opts.cwd or opts._cwd or vim.loop.cwd(), fullpath })
end
if vimcmd == "e"
Expand All @@ -128,7 +128,7 @@ M.vimcmd_file = function(vimcmd, selected, opts)
if vimcmd ~= "e" or curbuf ~= fullpath then
if entry.path then
-- do not run ':<cmd> <file>' for uri entries (#341)
local relpath = path.relative(entry.path, vim.loop.cwd())
local relpath = path.relative_to(entry.path, vim.loop.cwd())
if vim.o.autochdir then
-- force full paths when `autochdir=true` (#882)
relpath = fullpath
Expand Down Expand Up @@ -245,7 +245,7 @@ M.file_switch = function(selected, opts)
local bufnr = nil
local entry = path.entry_to_file(selected[1])
local fullpath = entry.path
if not path.starts_with_separator(fullpath) then
if not path.is_absolute(fullpath) then
fullpath = path.join({ opts.cwd or vim.loop.cwd(), fullpath })
end
for _, b in ipairs(vim.api.nvim_list_bufs()) do
Expand Down Expand Up @@ -629,7 +629,7 @@ end
local git_exec = function(selected, opts, cmd, silent)
local success
for _, e in ipairs(selected) do
local file = path.relative(path.entry_to_file(e, opts).path, opts.cwd)
local file = path.relative_to(path.entry_to_file(e, opts).path, opts.cwd)
local _cmd = vim.deepcopy(cmd)
table.insert(_cmd, file)
local output, rc = utils.io_systemlist(_cmd)
Expand Down Expand Up @@ -707,7 +707,7 @@ M.git_buf_edit = function(selected, opts)
local git_root = path.git_root(opts, true)
local win = vim.api.nvim_get_current_win()
local buffer_filetype = vim.bo.filetype
local file = path.relative(vim.fn.expand("%:p"), git_root)
local file = path.relative_to(vim.fn.expand("%:p"), git_root)
local commit_hash = match_commit_hash(selected[1], opts)
table.insert(cmd, commit_hash .. ":" .. file)
local git_file_contents = utils.io_systemlist(cmd)
Expand Down Expand Up @@ -816,8 +816,10 @@ end
---@param selected string[]
---@param opts table
M.apply_profile = function(selected, opts)
local fname = utils.__IS_WINDOWS and selected[1]:match("%u?:?[^:]+") or selected[1]:match("[^:]+")
local profile = selected[1]:match(":([^%s]+)")
local entry = path.entry_to_file(selected[1])
local fname = entry.path
local profile = entry.stripped:sub(#fname + 2):match("[^%s]+")
print(profile, fname)
local ok = utils.load_profile(fname, profile, opts.silent)
if ok then
vim.cmd(string.format([[lua require("fzf-lua").setup({"%s"})]], profile))
Expand Down
10 changes: 4 additions & 6 deletions lua/fzf-lua/complete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ local function find_toplevel_cwd(maybe_cwd, postfix, orig_cwd)
if vim.fn.isdirectory(vim.fn.expand(maybe_cwd)) == 1 then
local disp_cwd, cwd = maybe_cwd, vim.fn.expand(maybe_cwd)
-- returned cwd must be full path
if cwd:sub(1, 1) == "." and cwd:sub(2, 2) == path.SEPARATOR then
if path.has_cwd_prefix(cwd) then
cwd = vim.loop.cwd() .. (#cwd > 1 and cwd:sub(2) or "")
-- inject "./" only if original path started with it
-- otherwise ignore the "." retval from fnamemodify
if #orig_cwd > 0 and orig_cwd:sub(1, 1) ~= "." then
disp_cwd = nil
end
elseif not path.starts_with_separator(cwd) then
elseif not path.is_absolute(cwd) then
cwd = path.join({ vim.loop.cwd(), cwd })
end
return disp_cwd, cwd, postfix
Expand Down Expand Up @@ -60,15 +60,13 @@ local set_cmp_opts_path = function(opts)
if not opts.prompt then
opts.prompt = "."
end
if not path.ends_with_separator(opts.prompt) then
opts.prompt = opts.prompt .. path.SEPARATOR
end
opts.prompt = path.add_trailing(opts.prompt)
-- completion function rebuilds the line with the full path
opts.complete = function(selected, o, l, _)
-- query fuzzy matching is empty
if #selected == 0 then return end
local replace_at = col - #before
local relpath = path.relative(path.entry_to_file(selected[1], o).path, opts.cwd)
local relpath = path.relative_to(path.entry_to_file(selected[1], o).path, opts.cwd)
local before_path = replace_at > 1 and l:sub(1, replace_at - 1) or ""
local rest_of_line = #l >= (col + #after) and l:sub(col + #after) or ""
local resolved_path = opts._cwd and path.join({ opts._cwd, relpath }) or relpath
Expand Down
5 changes: 2 additions & 3 deletions lua/fzf-lua/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ if utils.__HAS_DEVICONS then

-- get the devicons module path
M._devicons_path = M._has_devicons and M._devicons and M._devicons.setup
and debug.getinfo(M._devicons.setup, "S").source:gsub("^@", "")
if utils.__IS_WINDOWS then M._devicons_path = vim.fs.normalize(M._devicons_path) end
and path.normalize(debug.getinfo(M._devicons.setup, "S").source:gsub("^@", ""))
end

M._diricon_escseq = function()
Expand Down Expand Up @@ -428,7 +427,7 @@ function M.normalize_opts(opts, globals, __resume_key)
-- relative paths in cwd are inaccessible when using multiprocess
-- as the external process have no awareness of our current working
-- directory so we must convert to full path (#375)
if not path.starts_with_separator(opts.cwd) then
if not path.is_absolute(opts.cwd) then
opts.cwd = path.join({ vim.loop.cwd(), opts.cwd })
end
end
Expand Down
Loading

0 comments on commit d39677f

Please sign in to comment.