0

Problem:

Suppose I have the following text in my vim buffer:

This is a commit msg.

Suppose further I have a git repo located at ~/my_repo.

Goal: Make a vim script so that I can highlight the text above, and have it sent as a git commit message within ~/my_repo. It would look something like

:'<,'>Commit ~/my_repo

It would also have auto-complete on its repo argument.

Attempted Solution:

First, the autocomplete function (AFAIK I think this is OK?):

function! GitLocations()
  return find $HOME -name '.git' -printf '%h\n' "generates a list of all folders which contain a .git dir
endfunction 

Next, the actual git commit function, which is incomplete:

function! CommitTextGitRepo(l1, l2, loc)
  let s:msg = ??? " how do I make this the highlighted text from line l1 to line l2?
  execute '!cd ' . a:loc . '&& git commit --allow-empty -m \"' . s:msg '\"'
endfunction

Assuming I can figure out how to get CommitTextGitRepo() working above, the final thing I would need is this (I think):

command! -nargs=* -complete=custom,GitLocations -range Commit call CommitToGitRepo(<line1>, <line2>, <q-args>)

I'm so close. How do I finish this up? :)

4

1 に答える 1