Skip to content

Instantly share code, notes, and snippets.

@avdgaag
Created July 28, 2014 18:26
Show Gist options
  • Save avdgaag/db9453f14a26bc4cb19c to your computer and use it in GitHub Desktop.
Save avdgaag/db9453f14a26bc4cb19c to your computer and use it in GitHub Desktop.

Revisions

  1. avdgaag created this gist Jul 28, 2014.
    29 changes: 29 additions & 0 deletions issue-completion.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    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