summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFarbod Salamat-Zadeh <12140044+farbodsz@users.noreply.github.com>2021-12-06 20:20:37 +0000
committerGitHub <noreply@github.com>2021-12-06 21:20:37 +0100
commit6b1579741a0e8f1e0e63d0c6c364b968c157338e (patch)
tree297e1c6df710d2fb16e716b76a9c3d482728ed88
parenta20f01353bde239e931c3c461fd3ef2d160a4f9b (diff)
fix: git stash entry formatting (#1452)
-rw-r--r--doc/telescope.txt2
-rw-r--r--lua/telescope/builtin/git.lua3
-rw-r--r--lua/telescope/builtin/init.lua1
-rw-r--r--lua/telescope/make_entry.lua34
4 files changed, 34 insertions, 6 deletions
diff --git a/doc/telescope.txt b/doc/telescope.txt
index d453e5f..45ce291 100644
--- a/doc/telescope.txt
+++ b/doc/telescope.txt
@@ -989,6 +989,8 @@ builtin.git_stash({opts}) *builtin.git_stash()*
{cwd} (string) specify the path of the repo
{use_git_root} (boolean) if we should use git root as cwd or the cwd
(important for submodule) (default: true)
+ {show_branch} (boolean) if we should display the branch name for git
+ stash entries (default: true)
builtin.builtin({opts}) *builtin.builtin()*
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