mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 01:50:05 +08:00
feat(git): rewrite :Git config
in lua
This commit is contained in:
parent
fe719db366
commit
23446bed8f
93
bundle/git.vim/lua/git/command/config.lua
Normal file
93
bundle/git.vim/lua/git/command/config.lua
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
--=============================================================================
|
||||||
|
-- config.lua --- git config
|
||||||
|
-- Copyright (c) 2016-2022 Wang Shidong & Contributors
|
||||||
|
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
||||||
|
-- URL: https://spacevim.org
|
||||||
|
-- License: GPLv3
|
||||||
|
--=============================================================================
|
||||||
|
|
||||||
|
local job = require('spacevim.api.job')
|
||||||
|
|
||||||
|
local log = require('git.log')
|
||||||
|
|
||||||
|
local jobid = -1
|
||||||
|
|
||||||
|
local config_bufid = -1
|
||||||
|
|
||||||
|
local config_stdout = {}
|
||||||
|
|
||||||
|
local function open_config_buf(len)
|
||||||
|
if len > 10 then
|
||||||
|
len = 10
|
||||||
|
elseif len < 5 then
|
||||||
|
len = 5
|
||||||
|
end
|
||||||
|
vim.cmd(len .. 'split git://config')
|
||||||
|
|
||||||
|
vim.cmd([[
|
||||||
|
normal! "_dd
|
||||||
|
setl nobuflisted
|
||||||
|
setl nomodifiable
|
||||||
|
setl nonumber norelativenumber
|
||||||
|
setl buftype=nofile
|
||||||
|
setf git-config
|
||||||
|
nnoremap <buffer><silent> q :bd!<CR>
|
||||||
|
]])
|
||||||
|
return vim.api.nvim_get_current_buf()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_stdout(id, data)
|
||||||
|
if id ~= jobid then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, v in ipairs(data) do
|
||||||
|
table.insert(config_stdout, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_stderr(id, data)
|
||||||
|
if id ~= jobid then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_exit(id, code, signal)
|
||||||
|
|
||||||
|
log.debug(string.format('git-config exit code %d, signal %d', code, signal))
|
||||||
|
if id ~= jobid then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if code == 0 and signal == 0 then
|
||||||
|
config_bufid = open_config_buf(#config_stdout)
|
||||||
|
vim.api.nvim_buf_set_option(config_bufid, 'modifiable', true)
|
||||||
|
vim.api.nvim_buf_set_lines(config_bufid, 0, -1, false, config_stdout)
|
||||||
|
vim.api.nvim_buf_set_option(config_bufid, 'modifiable', false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
run = function(argv)
|
||||||
|
|
||||||
|
local cmd = {'git', 'config'}
|
||||||
|
|
||||||
|
|
||||||
|
if #argv == 0 then
|
||||||
|
table.insert(cmd, '--list')
|
||||||
|
else
|
||||||
|
for _, v in ipairs(argv) do table.insert(cmd, v) end
|
||||||
|
end
|
||||||
|
|
||||||
|
log.debug(string.format('git-config cmd: %s', vim.inspect(cmd)))
|
||||||
|
|
||||||
|
jobid = job.start(cmd, {
|
||||||
|
on_stdout = on_stdout,
|
||||||
|
on_stderr = on_stderr,
|
||||||
|
on_exit = on_exit,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
}
|
@ -8,6 +8,7 @@ local cmds = {
|
|||||||
'blame',
|
'blame',
|
||||||
'branch',
|
'branch',
|
||||||
'checkout',
|
'checkout',
|
||||||
|
'config',
|
||||||
'cherry-pick',
|
'cherry-pick',
|
||||||
'clean',
|
'clean',
|
||||||
'commit',
|
'commit',
|
||||||
|
@ -27,7 +27,7 @@ If you have any suggestions , please checkout feedback section on [community](..
|
|||||||
- [x] `:Git cherry-pick`
|
- [x] `:Git cherry-pick`
|
||||||
- [x] `:Git clean`
|
- [x] `:Git clean`
|
||||||
- [x] `:Git commit`
|
- [x] `:Git commit`
|
||||||
- [ ] `:Git config`
|
- [x] `:Git config`
|
||||||
- [x] `:Git diff`
|
- [x] `:Git diff`
|
||||||
- [x] `:Git fetch`
|
- [x] `:Git fetch`
|
||||||
- [x] `:Git log`
|
- [x] `:Git log`
|
||||||
|
Loading…
Reference in New Issue
Block a user