feat: add icons and colors to telescope picker (#119)
* feat: add icons and colors to telescope picker * feat: add configuration options for telescope icons * fix: remove highlight group for telescope normal selectionmain
parent
ca9900c31e
commit
8fc97b6182
|
|
@ -170,6 +170,11 @@ require("persisted").setup({
|
||||||
copy_session = "<c-c>",
|
copy_session = "<c-c>",
|
||||||
delete_session = "<c-d>",
|
delete_session = "<c-d>",
|
||||||
},
|
},
|
||||||
|
icons = { -- icons displayed in the picker, set to nil to disable entirely
|
||||||
|
branch = " ",
|
||||||
|
dir = " ",
|
||||||
|
selected = " ",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -169,6 +169,11 @@ The plugin comes with the following defaults:
|
||||||
copy_session = "<c-c>",
|
copy_session = "<c-c>",
|
||||||
delete_session = "<c-d>",
|
delete_session = "<c-d>",
|
||||||
},
|
},
|
||||||
|
icons = { -- icons displayed in the picker, set to nil to disable entirely
|
||||||
|
branch = " ",
|
||||||
|
dir = " ",
|
||||||
|
selected = " ",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
<
|
<
|
||||||
|
|
|
||||||
|
|
@ -27,13 +27,18 @@ local defaults = {
|
||||||
copy_session = "<c-c>",
|
copy_session = "<c-c>",
|
||||||
delete_session = "<c-d>",
|
delete_session = "<c-d>",
|
||||||
},
|
},
|
||||||
|
icons = { -- icons displayed in the picker
|
||||||
|
branch = " ",
|
||||||
|
dir = " ",
|
||||||
|
selected = " ",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
M.options = {}
|
M.options = {}
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
M.options = vim.tbl_deep_extend("force", {}, defaults, opts or {})
|
M.options = vim.tbl_deep_extend("force", defaults, opts or {})
|
||||||
vim.fn.mkdir(M.options.save_dir, "p")
|
vim.fn.mkdir(M.options.save_dir, "p")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -367,11 +367,18 @@ function M.list()
|
||||||
dir_path = session_name
|
dir_path = session_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local f = io.popen("stat -f %a " .. session)
|
||||||
|
local last_modified = ""
|
||||||
|
if f then
|
||||||
|
last_modified = f:read()
|
||||||
|
end
|
||||||
|
|
||||||
table.insert(sessions, {
|
table.insert(sessions, {
|
||||||
["name"] = session_name,
|
["name"] = session_name,
|
||||||
["file_path"] = session,
|
["file_path"] = session,
|
||||||
["branch"] = branch,
|
["branch"] = branch,
|
||||||
["dir_path"] = dir_path,
|
["dir_path"] = dir_path,
|
||||||
|
["last_modified"] = last_modified,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,9 @@ end
|
||||||
|
|
||||||
return require("telescope").register_extension({
|
return require("telescope").register_extension({
|
||||||
setup = function(topts)
|
setup = function(topts)
|
||||||
|
vim.api.nvim_set_hl(0, "TelescopePersistedIsCurrent", { link = "TelescopeResultsOperator" })
|
||||||
|
vim.api.nvim_set_hl(0, "TelescopePersistedDir", { link = "Directory" })
|
||||||
|
vim.api.nvim_set_hl(0, "TelescopePersistedBranch", { link = "TelescopeResultsIdentifier" })
|
||||||
telescope_opts = topts
|
telescope_opts = topts
|
||||||
end,
|
end,
|
||||||
exports = {
|
exports = {
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,49 @@
|
||||||
|
local config = require("persisted.config")
|
||||||
local finders = require("telescope.finders")
|
local finders = require("telescope.finders")
|
||||||
local entry_display = require("telescope.pickers.entry_display")
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
local no_icons = {
|
||||||
|
branch = "",
|
||||||
|
dir = "",
|
||||||
|
selected = "",
|
||||||
|
}
|
||||||
|
|
||||||
M.session_finder = function(sessions)
|
M.session_finder = function(sessions)
|
||||||
-- Layout borrowed from:
|
local icons = vim.tbl_extend("force", no_icons, config.options.telescope.icons or {})
|
||||||
---https://github.com/LinArcX/telescope-env.nvim/blob/master/lua/telescope/_extensions/env.lua
|
|
||||||
|
|
||||||
local displayer = entry_display.create({
|
local custom_displayer = function(session)
|
||||||
items = {
|
local final_str = ""
|
||||||
{ remaining = true },
|
local hls = {}
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
local make_display = function(session)
|
local function append(str, hl)
|
||||||
local str
|
local hl_start = #final_str
|
||||||
|
final_str = final_str .. str
|
||||||
|
if hl then
|
||||||
|
table.insert(hls, { { hl_start, #final_str }, hl })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- is current session
|
||||||
|
append(session.file_path == vim.v.this_session and (icons.selected .. " ") or " ", "TelescopePersistedIsCurrent")
|
||||||
|
|
||||||
|
-- session path
|
||||||
|
append(icons.dir, "TelescopePersistedDir")
|
||||||
|
append(session.dir_path)
|
||||||
|
|
||||||
|
-- branch
|
||||||
if session.branch then
|
if session.branch then
|
||||||
str = string.format("%s (branch: %s)", session.dir_path, session.branch)
|
append(" " .. icons.branch .. session.branch, "TelescopePersistedBranch")
|
||||||
else
|
|
||||||
str = session.dir_path
|
|
||||||
end
|
end
|
||||||
if session.file_path == vim.v.this_session then
|
|
||||||
str = "* " .. str
|
return final_str, hls
|
||||||
end
|
|
||||||
return displayer({ str })
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return finders.new_table({
|
return finders.new_table({
|
||||||
results = sessions,
|
results = sessions,
|
||||||
entry_maker = function(session)
|
entry_maker = function(session)
|
||||||
session.ordinal = session.name
|
session.ordinal = session.name
|
||||||
session.display = make_display
|
session.display = custom_displayer
|
||||||
session.name = session.name
|
session.name = session.name
|
||||||
session.branch = session.branch
|
session.branch = session.branch
|
||||||
session.file_path = session.file_path
|
session.file_path = session.file_path
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue