Created
July 28, 2014 18:26
Autocomplete Github issue numbers from Vim using a custom completion function, Ruby and the Github API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! MyOmniFunc(findstart, base) | |
if a:findstart | |
let existing = matchstr(getline('.')[0:col('.')-1],'#\d*$') | |
return col('.')-1-strlen(existing) | |
endif | |
ruby << EOF | |
require 'open-uri' | |
require 'json' | |
def issues(repo, token) | |
JSON.parse( | |
open( | |
sprintf('https://api.github.com/repos/%s/issues', repo), | |
http_basic_authentication: [token, 'x-oauth-basic'] | |
).string | |
).map do |issue| | |
sprintf( | |
%Q|{ "word": "#%s", "menu": "%s" }|, | |
*issue.values_at('number', 'title') | |
) | |
end | |
end | |
iss = issues('USERNAME/PROJECT', 'TOKEN') | |
VIM.command("return [#{iss.join ','}]") | |
EOF | |
endfunction | |
set omnifunc=MyOmniFunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment