summaryrefslogtreecommitdiff
path: root/lua/telescope/actions/init.lua
diff options
context:
space:
mode:
authorCedric M'Passi <cempassi@student.42.fr>2020-11-27 12:15:02 +0100
committerGitHub <noreply@github.com>2020-11-27 14:15:02 +0300
commit6edbd1db5f1195445b8f8fc24ff982f6d36efd11 (patch)
tree34997f6f6e683855564c18d0388f21851435cb90 /lua/telescope/actions/init.lua
parent4a8ea7763ec3c1c0672398418da682c1e0d4017d (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/actions/init.lua')
-rw-r--r--lua/telescope/actions/init.lua15
1 files changed, 12 insertions, 3 deletions
diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua
index 527e0b5..4b152b6 100644
--- a/lua/telescope/actions/init.lua
+++ b/lua/telescope/actions/init.lua
@@ -243,11 +243,20 @@ actions.git_checkout = function(prompt_bufnr)
os.execute('git checkout ' .. val)
end
-actions.git_add = function(prompt_bufnr)
+actions.git_staging_toggle = function(prompt_bufnr)
local selection = actions.get_selected_entry(prompt_bufnr)
+
+ -- If parts of the file are staged and unstaged at the same time, stage
+ -- changes. Else toggle between staged and unstaged if the file is tracked,
+ -- and between added and untracked if the file is untracked.
+ if selection.status:sub(2) == ' ' then
+ os.execute('git restore --staged ' .. selection.value)
+ else
+ os.execute('git add ' .. selection.value)
+ end
actions.close(prompt_bufnr)
- local val = selection.value
- os.execute('git add ' .. val)
+ require('telescope.builtin').git_status()
+ vim.api.nvim_feedkeys('i', 'n', false)
end
-- ==================================================