diff --git a/bundle/git.vim/lua/git/command/config.lua b/bundle/git.vim/lua/git/command/config.lua new file mode 100644 index 000000000..f603263b5 --- /dev/null +++ b/bundle/git.vim/lua/git/command/config.lua @@ -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 q :bd! + ]]) + 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 +} diff --git a/bundle/git.vim/lua/git/init.lua b/bundle/git.vim/lua/git/init.lua index 318d15e72..f9659f54d 100644 --- a/bundle/git.vim/lua/git/init.lua +++ b/bundle/git.vim/lua/git/init.lua @@ -8,6 +8,7 @@ local cmds = { 'blame', 'branch', 'checkout', + 'config', 'cherry-pick', 'clean', 'commit', diff --git a/docs/roadmap.md b/docs/roadmap.md index a32099598..16346f5e3 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -27,7 +27,7 @@ If you have any suggestions , please checkout feedback section on [community](.. - [x] `:Git cherry-pick` - [x] `:Git clean` - [x] `:Git commit` - - [ ] `:Git config` + - [x] `:Git config` - [x] `:Git diff` - [x] `:Git fetch` - [x] `:Git log`