Skip to content

Commit 42c0ac8

Browse files
committed
feat(profiles): new default-title profile
- Cleans the prompt in favor of window title - Improvements to Telescope profile (uses titles, better hls) Also includes ability to combine more than one profile as base: ```lua :lua require"fzf-lua".setup({{"telescope","fzf-native"},<setup opts>}) ```
1 parent 97a88bb commit 42c0ac8

File tree

10 files changed

+125
-92
lines changed

10 files changed

+125
-92
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ telescope defaults with `bat` previewer:
448448
:lua require"fzf-lua".setup({"telescope",winopts={preview={default="bat"}}})
449449
```
450450

451+
Combining of profiles is also available by sending table instead of string as
452+
the first argument:
453+
```lua
454+
:lua require"fzf-lua".setup({{"telescope","fzf-native"},winopts={fullscreen=true}})
455+
```
456+
451457
See [profiles](https://github.com/ibhagwan/fzf-lua/tree/main/lua/fzf-lua/profiles)
452458
for more info.
453459

lua/fzf-lua/actions.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,9 +874,9 @@ M.apply_profile = function(selected, opts)
874874
local entry = path.entry_to_file(selected[1])
875875
local fname = entry.path
876876
local profile = entry.stripped:sub(#fname + 2):match("[^%s]+")
877-
local ok = utils.load_profile(fname, profile, opts.silent)
877+
local ok = utils.load_profile_fname(fname, profile, opts.silent)
878878
if ok then
879-
vim.cmd(string.format([[lua require("fzf-lua").setup({"%s"})]], profile))
879+
loadstring(string.format([[require("fzf-lua").setup({"%s"})]], profile))()
880880
end
881881
end
882882

lua/fzf-lua/init.lua

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,36 @@ end
138138
-- case the user decides not to call `setup()`
139139
M.setup_highlights()
140140

141-
function M.load_profile(profile)
142-
local fname = path.join({ vim.g.fzf_lua_directory, "profiles", profile .. ".lua" })
143-
return utils.load_profile(fname, nil, true)
144-
end
145-
146-
function M.setup(opts, do_not_reset_defaults)
147-
opts = type(opts) == "table" and opts or {}
148-
if type(opts[1]) == "string" then
149-
-- Did the user request a specific profile?
150-
local profile_opts = M.load_profile(opts[1])
141+
local function load_profiles(profiles)
142+
local ret = {}
143+
profiles = type(profiles) == "table" and profiles
144+
or type(profiles) == "string" and { profiles }
145+
or {}
146+
for _, profile in ipairs(profiles) do
147+
local fname = path.join({ vim.g.fzf_lua_directory, "profiles", profile .. ".lua" })
148+
local profile_opts = utils.load_profile_fname(fname, nil, true)
151149
if type(profile_opts) == "table" then
150+
if profile_opts[1] then
151+
-- profile requires loading base profile(s)
152+
profile_opts = vim.tbl_deep_extend("keep",
153+
profile_opts, load_profiles(profile_opts[1]))
154+
end
152155
if type(profile_opts.fn_load) == "function" then
153156
profile_opts.fn_load()
154157
profile_opts.fn_load = nil
155158
end
156-
opts = vim.tbl_deep_extend("keep", opts, profile_opts)
159+
ret = vim.tbl_deep_extend("force", ret, profile_opts)
157160
end
158161
end
162+
return ret
163+
end
164+
165+
function M.setup(opts, do_not_reset_defaults)
166+
opts = type(opts) == "table" and opts or {}
167+
if opts[1] then
168+
-- Did the user supply profile(s) to load?
169+
opts = vim.tbl_deep_extend("keep", opts, load_profiles(opts[1]))
170+
end
159171
if do_not_reset_defaults then
160172
-- no defaults reset requested, merge with previous setup options
161173
opts = vim.tbl_deep_extend("keep", opts, config.setup_opts or {})
@@ -342,7 +354,6 @@ M._exported_modules = {
342354

343355
-- excluded from builtin / auto-complete
344356
M._excluded_meta = {
345-
"load_profile",
346357
"setup",
347358
"fzf",
348359
"fzf_raw",

lua/fzf-lua/profiles/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ telescope defaults with `bat` previewer:
1919
| Profile | Details |
2020
| ---------------- | ------------------------------------------ |
2121
| `default` | fzf-lua defaults, uses neovim "builtin" previewer and devicons (if available) for git/files/buffers |
22+
| `default-title` | fzf-lua defaults, using title instead of prompt |
2223
| `fzf-native` | utilizes fzf's native previewing ability in the terminal where possible using `bat` for previews |
2324
| `fzf-tmux` | similar to `fzf-native` and opens in a tmux popup (requires tmux > 3.2) |
2425
| `fzf-vim` | closest to `fzf.vim`'s defaults (+icons), also sets up user commands (`:Files`, `:Rg`, etc) |

lua/fzf-lua/profiles/borderless_full.lua

Lines changed: 6 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,95 +3,30 @@ local hls = {
33
sel = "PmenuSel",
44
title = "IncSearch"
55
}
6-
local function title(str, opts)
7-
return vim.tbl_deep_extend("keep", opts or {},
8-
{
9-
prompt = "",
10-
winopts = {
11-
-- title = { { " " .. str .. " ", hls.title } },
12-
title = " " .. str .. " ",
13-
title_pos = "center",
14-
}
15-
})
16-
end
176
return {
18-
desc = "borderless and not so minimalistic",
19-
winopts = {
7+
{ "default-title" }, -- base profile
8+
desc = "borderless and not so minimalistic",
9+
winopts = {
2010
border = { " ", " ", " ", " ", " ", " ", " ", " " },
2111
preview = {
2212
scrollbar = "float",
2313
scrolloff = "-2",
2414
title_pos = "center",
2515
},
2616
},
27-
hls = {
17+
hls = {
2818
title = hls.title,
2919
border = hls.bg,
3020
preview_title = hls.title,
3121
preview_border = hls.bg,
3222
scrollfloat_e = "",
3323
scrollfloat_f = hls.sel,
3424
},
35-
fzf_colors = {
25+
fzf_colors = {
3626
["gutter"] = { "bg", hls.bg },
3727
["bg"] = { "bg", hls.bg },
3828
["bg+"] = { "bg", hls.sel },
3929
["fg+"] = { "fg", hls.sel },
4030
},
41-
files = title("Files"),
42-
buffers = title("Buffers"),
43-
tabs = title("Tabs"),
44-
lines = title("Lines"),
45-
blines = title("Buffer Lines"),
46-
grep = title("Search", { rg_glob = true }),
47-
git = {
48-
files = title("Git Files"),
49-
status = title("Git Status"),
50-
commits = title("Git Commits"),
51-
bcommits = title("Git BCommits"),
52-
branches = title("Git Branches"),
53-
stash = title("Git Stash"),
54-
},
55-
args = title("Args"),
56-
oldfiles = title("Oldfiles"),
57-
quickfix = title("Quickfix List"),
58-
quickfix_stack = title("Quickfix List Stack"),
59-
loclist = title("Location List"),
60-
loclist_stack = title("Location List Stack"),
61-
tags = title("Tags"),
62-
btags = title("Buffer Tags"),
63-
colorschemes = title("Colorschemes"),
64-
highlights = title("Highlights"),
65-
helptags = title("Neovim Help"),
66-
manpages = title("Man Pages"),
67-
lsp = title("LSP", {
68-
prompt = false,
69-
symbols = title("LSP", { prompt = false }),
70-
finder = title("LSP Finder"),
71-
code_actions = title("Code Actions"),
72-
}),
73-
diagnostics = title("Diagnostics"),
74-
builtin = title("FzfLua Builtin"),
75-
profiles = title("FzfLua Profiles"),
76-
marks = title("Marks"),
77-
jumps = title("Jumps"),
78-
tagstack = title("Tagstack"),
79-
commands = title("Commands"),
80-
autocmds = title("Autocmds"),
81-
command_history = title("Command history"),
82-
search_history = title("Search history"),
83-
registers = title("Registers"),
84-
keymaps = title("Keymaps"),
85-
spell_suggest = title("Spell Suggestions"),
86-
filetypes = title("Filetypes"),
87-
packadd = title("Packer Packadd"),
88-
menus = title("Menus"),
89-
tmux = title("Tmux Buffers"),
90-
dap = {
91-
commands = title("DAP Commands"),
92-
configurations = title("DAP Configurations"),
93-
variables = title("DAP Variables"),
94-
frames = title("DAP Frames"),
95-
breakpoints = title("DAP Breakpoints"),
96-
},
31+
grep = { rg_glob = true },
9732
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
local function title(str, opts)
2+
return vim.tbl_deep_extend("keep", opts or {},
3+
{
4+
prompt = false,
5+
winopts = {
6+
-- title = { { " " .. str .. " ", hls.title } },
7+
title = " " .. str .. " ",
8+
title_pos = "center",
9+
}
10+
})
11+
end
12+
return {
13+
desc = "defaults using title instead of prompt",
14+
files = title("Files"),
15+
buffers = title("Buffers"),
16+
tabs = title("Tabs"),
17+
lines = title("Lines"),
18+
blines = title("Buffer Lines"),
19+
grep = title("Grep", { prompt = "> " }),
20+
git = {
21+
files = title("Git Files"),
22+
status = title("Git Status"),
23+
commits = title("Git Commits"),
24+
bcommits = title("Git BCommits"),
25+
branches = title("Git Branches"),
26+
stash = title("Git Stash"),
27+
},
28+
args = title("Args"),
29+
oldfiles = title("Oldfiles"),
30+
quickfix = title("Quickfix List"),
31+
quickfix_stack = title("Quickfix List Stack"),
32+
loclist = title("Location List"),
33+
loclist_stack = title("Location List Stack"),
34+
tags = title("Tags"),
35+
btags = title("Buffer Tags"),
36+
colorschemes = title("Colorschemes"),
37+
awesome_colorschemes = title("Awesome Colorschemes"),
38+
highlights = title("Highlights"),
39+
helptags = title("Neovim Help"),
40+
manpages = title("Man Pages"),
41+
lsp = {
42+
title_prefix = "LSP",
43+
winopts = { title_pos = "center" },
44+
symbols = { title_prefix = "LSP", winopts = { title_pos = "center" } },
45+
finder = title("LSP Finder"),
46+
code_actions = title("Code Actions"),
47+
},
48+
diagnostics = title("Diagnostics"),
49+
builtin = title("FzfLua Builtin"),
50+
profiles = title("FzfLua Profiles"),
51+
marks = title("Marks"),
52+
jumps = title("Jumps"),
53+
tagstack = title("Tagstack"),
54+
commands = title("Commands"),
55+
autocmds = title("Autocmds"),
56+
command_history = title("Command history"),
57+
search_history = title("Search history"),
58+
registers = title("Registers"),
59+
keymaps = title("Keymaps"),
60+
spell_suggest = title("Spell Suggestions"),
61+
filetypes = title("Filetypes"),
62+
packadd = title("Packer Packadd"),
63+
menus = title("Menus"),
64+
tmux = title("Tmux Buffers"),
65+
dap = {
66+
commands = title("DAP Commands"),
67+
configurations = title("DAP Configurations"),
68+
variables = title("DAP Variables"),
69+
frames = title("DAP Frames"),
70+
breakpoints = title("DAP Breakpoints"),
71+
},
72+
}

lua/fzf-lua/profiles/telescope.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local function hl_validate(hl)
66
end
77

88
return {
9+
{ "default-title" }, -- base profile
910
desc = "match telescope default highlights|keybinds",
1011
fzf_opts = { ["--layout"] = "default", ["--marker"] = "+" },
1112
winopts = {
@@ -17,21 +18,23 @@ return {
1718
horizontal = "right:50%",
1819
layout = "flex",
1920
flip_columns = 120,
21+
delay = 10,
22+
winopts = { number = false },
2023
},
2124
},
2225
hls = {
2326
normal = hl_validate "TelescopeNormal",
2427
border = hl_validate "TelescopeBorder",
25-
title = hl_validate "TelescopeTitle",
28+
title = hl_validate "TelescopePromptTitle",
2629
help_normal = hl_validate "TelescopeNormal",
2730
help_border = hl_validate "TelescopeBorder",
2831
preview_normal = hl_validate "TelescopeNormal",
2932
preview_border = hl_validate "TelescopeBorder",
30-
preview_title = hl_validate "TelescopeTitle",
33+
preview_title = hl_validate "TelescopePreviewTitle",
3134
-- builtin preview only
3235
cursor = hl_validate "Cursor",
33-
cursorline = hl_validate "TelescopePreviewLine",
34-
cursorlinenr = hl_validate "TelescopePreviewLine",
36+
cursorline = hl_validate "TelescopeSelection",
37+
cursorlinenr = hl_validate "TelescopeSelection",
3538
search = hl_validate "IncSearch",
3639
},
3740
fzf_colors = {
@@ -44,6 +47,7 @@ return {
4447
["info"] = { "fg", "TelescopeMultiSelection" },
4548
["border"] = { "fg", "TelescopeBorder" },
4649
["gutter"] = { "bg", "TelescopeNormal" },
50+
["query"] = { "fg", "TelescopePromptNormal" },
4751
["prompt"] = { "fg", "TelescopePromptPrefix" },
4852
["pointer"] = { "fg", "TelescopeSelectionCaret" },
4953
["marker"] = { "fg", "TelescopeSelectionCaret" },

lua/fzf-lua/providers/lsp.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,11 @@ local normalize_lsp_opts = function(opts, cfg, __resume_key)
559559
opts = config.normalize_opts(opts, cfg, __resume_key)
560560
if not opts then return end
561561

562-
if not opts.prompt and opts.prompt_postfix then
562+
-- `title_prefix` is priortized over both `prompt` and `prompt_prefix`
563+
if (not opts.winopts or opts.winopts.title == nil) and opts.title_prefix then
564+
utils.map_set(opts,
565+
"winopts.title", string.format(" %s %s ", opts.title_prefix, opts.lsp_handler.label))
566+
elseif opts.prompt == nil and opts.prompt_postfix then
563567
opts.prompt = opts.lsp_handler.label .. (opts.prompt_postfix or "")
564568
end
565569

lua/fzf-lua/providers/module.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ M.profiles = function(opts)
7171
local ext = path.extension(fname)
7272
if type == "file" and ext == "lua" then
7373
local profile = name:sub(1, #name - 4)
74-
local res = utils.load_profile(fname, profile, true)
74+
local res = utils.load_profile_fname(fname, profile, true)
7575
if res then
7676
local entry = string.format("%s:%-30s%s", fname,
7777
utils.ansi_codes.yellow(profile), res.desc or "")

lua/fzf-lua/utils.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ end
765765
---@param fname string
766766
---@param name string|nil
767767
---@param silent boolean
768-
function M.load_profile(fname, name, silent)
768+
function M.load_profile_fname(fname, name, silent)
769769
local profile = name or fname:match("([^%p]+)%.lua$") or "<unknown>"
770770
local ok, res = pcall(dofile, fname)
771771
if ok and type(res) == "table" then

0 commit comments

Comments
 (0)