Skip to content

Instantly share code, notes, and snippets.

@dkarter
Last active May 9, 2018 15:31
Show Gist options
  • Save dkarter/e2402f3fddf8c824dd2bbb88345236d8 to your computer and use it in GitHub Desktop.
Save dkarter/e2402f3fddf8c824dd2bbb88345236d8 to your computer and use it in GitHub Desktop.
Pivotal Story Completion

Pivotal Story ID Completion in Vim:

DEMO

preview

Setup

Add this to your .vimrc:

fun! s:parse_pivotal_story(entry)
    let l:stories = pivotaltracker#stories('', '')
    let l:filtered = filter(l:stories, {idx, val -> val.menu == a:entry[0]})
    return l:filtered[0].word
 endfun

 inoremap <expr> <c-x><c-s> fzf#complete(
       \ {
       \ 'source': map(pivotaltracker#stories('', ''), {_key, val -> val.menu}),
       \ 'reducer': function('<sid>parse_pivotal_story'),
       \ 'options': '-m',
       \ 'down': '20%'
       \ })

Add these plugins to vim with your favorite plugin manager. I use Plug:

" fzf (fuzzy finding)
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' }
Plug 'junegunn/fzf.vim'

" Complete pivotal tracker story ids
Plug 'hauleth/pivotaltracker.vim'

Usage

In INSERT MODE press <c-x><c-s> search for a story title and press <CR> when done.

Pivotal Login

To enable this you would need to set environment variables in your system:

PIVOTAL_TOKEN

PIVOTAL_ID

  • Where to get it: It will be in the URL of your project in pivotal e.g. https://www.pivotaltracker.com/n/projects/[this number]
  • Where to set it: Either .zshrc.local (if you only ever work on one project); or use direnv to set it automatically when you cd into the directory of your project)

Notes

  • I am using FZF to fuzzy search story titles so it is a pre-req, but you don't have to use FZF for anything else unless you want to.
  • I've only tested this with NeoVim. Though I think it should work for Vim too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment