summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/builtin/git.lua3
-rw-r--r--lua/telescope/builtin/init.lua1
-rw-r--r--lua/telescope/make_entry.lua34
3 files changed, 32 insertions, 6 deletions
diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua
index a7a7b43..7bb7bfd 100644
--- a/lua/telescope/builtin/git.lua
+++ b/lua/telescope/builtin/git.lua
@@ -72,7 +72,8 @@ git.commits = function(opts)
end
git.stash = function(opts)
- opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_stash())
+ opts.show_branch = vim.F.if_nil(opts.show_branch, true)
+ opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_stash(opts))
pickers.new(opts, {
prompt_title = "Git Stash",
diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua
index 0a69aae..9330aec 100644
--- a/lua/telescope/builtin/init.lua
+++ b/lua/telescope/builtin/init.lua
@@ -204,6 +204,7 @@ builtin.git_status = require_on_exported_call("telescope.builtin.git").status
---@param opts table: options to pass to the picker
---@field cwd string: specify the path of the repo
---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true)
+---@field show_branch boolean: if we should display the branch name for git stash entries (default: true)
builtin.git_stash = require_on_exported_call("telescope.builtin.git").stash
--
diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua
index 18da57a..1e48c8c 100644
--- a/lua/telescope/make_entry.lua
+++ b/lua/telescope/make_entry.lua
@@ -249,16 +249,40 @@ do
end
end
-function make_entry.gen_from_git_stash()
+function make_entry.gen_from_git_stash(opts)
+ local displayer = entry_display.create {
+ separator = " ",
+ items = {
+ { width = 10 },
+ opts.show_branch and { width = 15 } or "",
+ { remaining = true },
+ },
+ }
+
+ local make_display = function(entry)
+ return displayer {
+ { entry.value, "TelescopeResultsLineNr" },
+ opts.show_branch and { entry.branch_name, "TelescopeResultsIdentifier" } or "",
+ entry.commit_info,
+ }
+ end
+
return function(entry)
if entry == "" then
return nil
end
- local splitted = vim.split(entry, ":")
+
+ local splitted = utils.max_split(entry, ": ", 2)
+ local stash_idx = splitted[1]
+ local _, branch_name = string.match(splitted[2], "^([WIP on|On]+) (.+)")
+ local commit_info = splitted[3]
+
return {
- value = splitted[1],
- ordinal = splitted[3],
- display = splitted[3],
+ value = stash_idx,
+ ordinal = commit_info,
+ branch_name = branch_name,
+ commit_info = commit_info,
+ display = make_display,
}
end
end