-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
406 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Fzf-Lua Options | ||
|
||
## Setup | ||
|
||
## Globals | ||
|
||
#### winopts.row | ||
|
||
Type: `number`, Default: `0.35` | ||
|
||
Screen row where to place the fzf-lua float window, between 0-1 will represent precentage of `vim.o.lines` (0: top, 1: bottom), if >= 1 will attempt to place the float in the exact screen line. | ||
|
||
#### winopts.col | ||
|
||
Type: `number`, Default: `0.55` | ||
|
||
Screen column where to place the fzf-lua float window, between 0-1 will represent precentage of `vim.o.columns` (0: leftmost, 1: rightmost), if >= 1 will attempt to place the float in the exact screen column. | ||
|
||
#### winopts.preview.border | ||
|
||
Type: `string`, Default: `border` | ||
|
||
Applies only to fzf native previewers (i.e. `bat`, `git_status`), set to `noborder` to hide the preview border, consult `man fzf` for all vailable options. | ||
|
||
### Cmd: files | ||
|
||
Files picker, will enumrate the filesystem of the current working directory using `fd`, `rg` and `grep` or `dir.exe`. | ||
|
||
#### files.cwd | ||
|
||
Type: `string`, Default: `nil` | ||
|
||
Sets the current working directory. | ||
|
||
#### files.cwd_prompt | ||
|
||
Type: `boolean`, Default: `true` | ||
|
||
Display the current working directory in the prompt (`fzf.vim` style). | ||
|
||
#### files.cwd_prompt_shorten_len | ||
|
||
Type: `number`, Default: `32` | ||
|
||
Prompt over this length will be shortened, e.g. `~/.config/nvim/lua/` will be shortened to `~/.c/n/lua/` (for more info see `:help pathshorten`). | ||
|
||
<sub><sup>*Requires `cwd_prompt=true`</sup></sub> | ||
|
||
#### files.cwd_prompt_shorten_val | ||
|
||
Type: `number`, Default: `1` | ||
|
||
Length of shortened prompt path parts, e.g. set to `2`, `~/.config/nvim/lua/` will be shortened to `~/.co/nv/lua/` (for more info see `:help pathshorten`). | ||
|
||
<sub><sup>*Requires `cwd_prompt=true`</sup></sub> | ||
|
||
<!--- vim: set nospell: --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
*fzf-lua-opts.txt* For Neovim >= 0.8.0 Last change: 2024 April 05 | ||
|
||
============================================================================== | ||
Table of Contents *fzf-lua-opts-table-of-contents* | ||
|
||
Setup ................................................... |fzf-lua-opts-setup| | ||
Globals ............................................... |fzf-lua-opts-globals| | ||
Cmd: files ......................................... |fzf-lua-opts-cmd:-files| | ||
|
||
============================================================================== | ||
FZF-LUA OPTIONS *fzf-lua-opts-fzf-lua-options* | ||
|
||
|
||
|
||
------------------------------------------------------------------------------ | ||
SETUP *fzf-lua-opts-setup* | ||
|
||
|
||
|
||
------------------------------------------------------------------------------ | ||
GLOBALS *fzf-lua-opts-globals* | ||
|
||
|
||
|
||
|
||
winopts.row *fzf-lua-opts-winopts.row* | ||
|
||
Type: `number`, Default: `0.35` | ||
|
||
Screen row where to place the fzf-lua float window, between 0-1 will represent | ||
precentage of `vim.o.lines` (0: top, 1: bottom), if >= 1 will attempt to place | ||
the float in the exact screen line. | ||
|
||
|
||
|
||
winopts.col *fzf-lua-opts-winopts.col* | ||
|
||
Type: `number`, Default: `0.55` | ||
|
||
Screen column where to place the fzf-lua float window, between 0-1 will | ||
represent precentage of `vim.o.columns` (0: leftmost, 1: rightmost), if >= 1 | ||
will attempt to place the float in the exact screen column. | ||
|
||
|
||
|
||
winopts.preview.border *fzf-lua-opts-winopts.preview.border* | ||
|
||
Type: `string`, Default: `border` | ||
|
||
Applies only to fzf native previewers (i.e. `bat`, `git_status`), set to | ||
`noborder` to hide the preview border, consult `man fzf` for all vailable | ||
options. | ||
|
||
|
||
|
||
CMD: FILES *fzf-lua-opts-cmd:-files* | ||
|
||
Files picker, will enumrate the filesystem of the current working directory | ||
using `fd`, `rg` and `grep` or `dir.exe`. | ||
|
||
|
||
|
||
files.cwd *fzf-lua-opts-files.cwd* | ||
|
||
Type: `string`, Default: `nil` | ||
|
||
Sets the current working directory. | ||
|
||
|
||
|
||
files.cwd_prompt *fzf-lua-opts-files.cwd_prompt* | ||
|
||
Type: `boolean`, Default: `true` | ||
|
||
Display the current working directory in the prompt (`fzf.vim` style). | ||
|
||
|
||
|
||
files.cwd_prompt_shorten_len *fzf-lua-opts-files.cwd_prompt_shorten_len* | ||
|
||
Type: `number`, Default: `32` | ||
|
||
Prompt over this length will be shortened, e.g. `~/.config/nvim/lua/` will be | ||
shortened to `~/.c/n/lua/` (for more info see `:help pathshorten`). | ||
|
||
<sub><sup>*Requires `cwd_prompt=true`</sup></sub> | ||
|
||
|
||
|
||
files.cwd_prompt_shorten_val *fzf-lua-opts-files.cwd_prompt_shorten_val* | ||
|
||
Type: `number`, Default: `1` | ||
|
||
Length of shortened prompt path parts, e.g. set to `2`, `~/.config/nvim/lua/` | ||
will be shortened to `~/.co/nv/lua/` (for more info see `:help pathshorten`). | ||
|
||
<sub><sup>*Requires `cwd_prompt=true`</sup></sub> | ||
|
||
|
||
vim:tw=78:ts=8:ft=help:norl: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,122 @@ | ||
-- Modified from Telescope 'command.lua' | ||
local builtin = require "fzf-lua" | ||
local utils = require "fzf-lua.utils" | ||
local command = {} | ||
|
||
local arg_value = { | ||
["nil"] = nil, | ||
['""'] = "", | ||
['"'] = "", | ||
} | ||
|
||
local bool_type = { | ||
["false"] = false, | ||
["true"] = true, | ||
} | ||
|
||
-- convert command line string arguments to | ||
-- lua number boolean type and nil values | ||
local function convert_user_opts(user_opts) | ||
local _switch = { | ||
["boolean"] = function(key, val) | ||
if val == "false" then | ||
user_opts[key] = false | ||
return | ||
end | ||
user_opts[key] = true | ||
end, | ||
["number"] = function(key, val) | ||
user_opts[key] = tonumber(val) | ||
end, | ||
["string"] = function(key, val) | ||
if arg_value[val] ~= nil then | ||
user_opts[key] = arg_value[val] | ||
return | ||
end | ||
local defaults = require "fzf-lua.defaults".defaults | ||
local serpent = require "fzf-lua.lib.serpent" | ||
|
||
if bool_type[val] ~= nil then | ||
user_opts[key] = bool_type[val] | ||
end | ||
end, | ||
} | ||
local M = {} | ||
|
||
local _switch_metatable = { | ||
__index = function(_, k) | ||
utils.info(string.format("Type of %s does not match", k)) | ||
end, | ||
} | ||
function M.run_command(cmd, ...) | ||
local args = { ... } | ||
cmd = cmd or "builtin" | ||
|
||
setmetatable(_switch, _switch_metatable) | ||
if not builtin[cmd] then | ||
utils.info(string.format("invalid command '%s'", cmd)) | ||
return | ||
end | ||
|
||
local opts = {} | ||
|
||
for key, val in pairs(user_opts) do | ||
_switch["string"](key, val) | ||
for _, arg in ipairs(args) do | ||
local key = arg:match("^[^=]+") | ||
local val = arg:match("=") and arg:match("=(.*)$") | ||
local ok, loaded = serpent.load(val or "true") | ||
if ok and (type(loaded) ~= "table" or not vim.tbl_isempty(loaded)) then | ||
opts[key] = loaded | ||
else | ||
opts[key] = val or true | ||
end | ||
end | ||
|
||
builtin[cmd](opts) | ||
end | ||
|
||
-- receive the viml command args | ||
-- it should output a table value like | ||
-- { | ||
-- cmd = 'files', | ||
-- opts = { | ||
-- cwd = '***', | ||
-- } | ||
local function run_command(args) | ||
local user_opts = args or {} | ||
if next(user_opts) == nil or not user_opts.cmd then | ||
utils.info("missing command args") | ||
return | ||
function M._candidates(line, cmp_items) | ||
local function to_cmp_items(t, data) | ||
local cmp = require("cmp") | ||
return vim.tbl_map(function(v) | ||
return { | ||
label = v, | ||
filterText = v, | ||
insertText = v, | ||
kind = cmp.lsp.CompletionItemKind.Variable, | ||
data = data, | ||
} | ||
end, t) | ||
end | ||
local builtin_list = vim.tbl_filter(function(k) | ||
return builtin._excluded_metamap[k] == nil | ||
end, vim.tbl_keys(builtin)) | ||
|
||
local cmd = user_opts.cmd | ||
local opts = user_opts.opts or {} | ||
local l = vim.split(line, "%s+") | ||
local n = #l - 2 | ||
|
||
if next(opts) ~= nil then | ||
convert_user_opts(opts) | ||
end | ||
if n == 0 then | ||
local commands = vim.tbl_flatten({ builtin_list }) | ||
table.sort(commands) | ||
|
||
if builtin[cmd] then | ||
builtin[cmd](opts) | ||
else | ||
utils.info(string.format("invalid command '%s'", cmd)) | ||
commands = vim.tbl_filter(function(val) | ||
return vim.startswith(val, l[2]) | ||
end, commands) | ||
|
||
return cmp_items and to_cmp_items(commands) or commands | ||
end | ||
end | ||
|
||
function command.load_command(cmd, ...) | ||
local args = { ... } | ||
if cmd == nil then | ||
run_command { cmd = "builtin" } | ||
return | ||
-- Not all commands have their opts under the same key | ||
local function cmd2key(cmd) | ||
local cmd2cfg = { | ||
{ | ||
patterns = { "^git_", "^dap", "^tmux_" }, | ||
transform = function(c) return c:gsub("_", ".") end | ||
}, | ||
{ | ||
patterns = { "^lsp_code_actions$" }, | ||
transform = function(_) return "lsp.code_actions" end | ||
}, | ||
{ patterns = { "^lsp_.*_symbols$" }, transform = function(_) return "lsp.symbols" end }, | ||
{ patterns = { "^lsp_" }, transform = function(_) return "lsp" end }, | ||
{ patterns = { "^diagnostics_" }, transform = function(_) return "dianostics" end }, | ||
{ patterns = { "^tags" }, transform = function(_) return "tags" end }, | ||
{ patterns = { "grep" }, transform = function(_) return "grep" end }, | ||
{ patterns = { "^complete_bline$" }, transform = function(_) return "complete_line" end }, | ||
} | ||
for _, v in pairs(cmd2cfg) do | ||
for _, p in ipairs(v.patterns) do | ||
if cmd:match(p) then return v.transform(cmd) end | ||
end | ||
end | ||
return cmd | ||
end | ||
|
||
local user_opts = {} | ||
user_opts["cmd"] = cmd | ||
user_opts.opts = {} | ||
local cmd_cfg_key = cmd2key(l[2]) | ||
local cmd_opts = utils.map_get(defaults, cmd_cfg_key) or {} | ||
local opts = vim.tbl_filter(function(k) | ||
return not k:match("^_") | ||
end, vim.tbl_keys(utils.map_flatten(cmd_opts))) | ||
|
||
-- Add globals recursively, e.g. `winopts.fullscreen` | ||
-- will be later retrieved using `utils.map_get(...)` | ||
for k, v in pairs({ | ||
winopts = false, | ||
keymap = false, | ||
fzf_opts = false, | ||
fzf_tmux_opts = false, | ||
__HLS = "hls", -- rename prefix | ||
}) do | ||
opts = vim.tbl_flatten({ opts, vim.tbl_keys(utils.map_flatten(defaults[k] or {}, v or k)) }) | ||
end | ||
|
||
for _, arg in ipairs(args) do | ||
local param = vim.split(arg, "=") | ||
user_opts.opts[param[1]] = param[2] | ||
-- Add generic options that apply to all pickers | ||
for _, o in ipairs({ "query" }) do | ||
table.insert(opts, o) | ||
end | ||
|
||
run_command(user_opts) | ||
table.sort(opts) | ||
|
||
opts = vim.tbl_filter(function(val) | ||
return vim.startswith(val, l[#l]) | ||
end, opts) | ||
|
||
return cmp_items and to_cmp_items(opts, { cmd = cmd_cfg_key }) or opts | ||
end | ||
|
||
return command | ||
return M |
Oops, something went wrong.