diff options
| author | Cedric M'Passi <cempassi@student.42.fr> | 2020-11-27 12:15:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-27 14:15:02 +0300 |
| commit | 6edbd1db5f1195445b8f8fc24ff982f6d36efd11 (patch) | |
| tree | 34997f6f6e683855564c18d0388f21851435cb90 /lua/telescope/builtin/git.lua | |
| parent | 4a8ea7763ec3c1c0672398418da682c1e0d4017d (diff) | |
feat: Make tab toggle between git add and git restore in builtin.git_status() (#289)
Very useful functionality to use git_status for. Now users can add a file or restore it by <tab>
authored by: @cempassi
Diffstat (limited to 'lua/telescope/builtin/git.lua')
| -rw-r--r-- | lua/telescope/builtin/git.lua | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua index 16d4554..2122fb9 100644 --- a/lua/telescope/builtin/git.lua +++ b/lua/telescope/builtin/git.lua @@ -106,18 +106,9 @@ git.branches = function(opts) end git.status = function(opts) - local output = vim.split(utils.get_os_command_output('git status -s'), '\n') - local results = {} - for _, v in ipairs(output) do - if v ~= "" then - local mod, fname = string.match(v, '(..)%s(.+)') - if mod ~= 'A ' and mod ~= 'M ' and mod ~= 'R ' and mod ~= 'D ' then - table.insert(results, { mod = mod, file = fname }) - end - end - end + local output = utils.get_os_command_output('git status -s') - if vim.tbl_isempty(results) then + if output == '' then print('No changes found') return end @@ -125,19 +116,23 @@ git.status = function(opts) pickers.new(opts, { prompt_title = 'Git Status', finder = finders.new_table { - results = results, + results = vim.split(output, '\n'), entry_maker = function(entry) + if entry == '' then return nil end + local mod, file = string.match(entry, '(..).*%s[->%s]?(.+)') return { - value = entry.file, - ordinal = entry.mod .. ' ' .. entry.file, - display = entry.mod .. ' ' .. entry.file, + value = file, + status = mod, + ordinal = entry, + display = entry, } end }, previewer = previewers.git_file_diff.new(opts), sorter = conf.file_sorter(opts), - attach_mappings = function() - actions.goto_file_selection_edit:replace(actions.git_add) + attach_mappings = function(_, map) + map('i', '<tab>', actions.git_staging_toggle) + map('n', '<tab>', actions.git_staging_toggle) return true end }):find() |
