From 6b1579741a0e8f1e0e63d0c6c364b968c157338e Mon Sep 17 00:00:00 2001 From: Farbod Salamat-Zadeh <12140044+farbodsz@users.noreply.github.com> Date: Mon, 6 Dec 2021 20:20:37 +0000 Subject: fix: git stash entry formatting (#1452) --- lua/telescope/make_entry.lua | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'lua/telescope/make_entry.lua') 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 -- cgit v1.2.3