Skip to content

Instantly share code, notes, and snippets.

@avdgaag
Created July 28, 2014 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avdgaag/db9453f14a26bc4cb19c to your computer and use it in GitHub Desktop.
Save avdgaag/db9453f14a26bc4cb19c to your computer and use it in GitHub Desktop.
Autocomplete Github issue numbers from Vim using a custom completion function, Ruby and the Github API.
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