forked from hypoport/trello_cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrello_vimrc
174 lines (152 loc) · 5.6 KB
/
trello_vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
" This callback will be executed when the entire command is completed
function! BackgroundCommandClose(channel)
let a:save_pos = getpos(".")
execute '%! cat ' . g:backgroundCommandOutput
call setpos('.', a:save_pos)
execute('redraw!')
execute('set filetype=markdown')
unlet a:save_pos
unlet g:backgroundCommandOutput
endfunction
function! RunBackgroundCommand(command)
" Make sure we're running VIM version 8 or higher.
" RunBackgroundCommand requires VIM version 8 or higher
if v:version < 800
let g:save_pos = getpos(".")
execute('% ! ' . a:command)
call setpos('.', g:save_pos)
return
endif
if exists('g:backgroundCommandOutput')
echo 'Already running task in background'
else
echo 'Running task in background'
" Launch the job.
" Notice that we're only capturing out, and not err here. This is because, for some reason, the callback
" will not actually get hit if we write err out to the same file. Not sure if I'm doing this wrong or?
let g:backgroundCommandOutput = tempname()
call job_start(a:command, {'close_cb': 'BackgroundCommandClose', 'out_io': 'file', 'out_name': g:backgroundCommandOutput})
endif
endfunction
function! OpenTrelloExternal()
let a:line = getline('.')
if match(a:line, "^\* <[^>]*>") != -1
let a:link = substitute(a:line, '^\* <\([^>]*\)>.*$', '\1', 'g')
call system ('browser_open_url -f "https://trello.com/c/' . a:link . '"')
elseif match(a:line, "^# <[^>]*>") != -1
let a:link = substitute(a:line, '^# <\([^>]*\)>.*$', '\1', 'g')
call system ('browser_open_url -f "https://trello.com/b/' . a:link . '"')
endif
endfunction
function! OpenTrello()
let a:line = getline('.')
silent ! pass foo/foo
if match(a:line, "^\* <[^>]*>") != -1
let a:link = substitute(a:line, '^\* <\([^>]*\)>.*$', '\1', 'g')
execute('%! clitrello card ' . a:link . ' | jq . ')
set filetype=json
elseif match(a:line, "^# <[^>]*>") != -1
let a:link = substitute(a:line, '^# <\([^>]*\)>.*$', '\1', 'g')
execute('%! clitrello board_cards ' . a:link . ' cards_markdown')
set filetype=markdown
elseif match(a:line, "^## <[^>]*>") != -1
let a:link = substitute(a:line, '^## <\([^>]*\)>.*$', '\1', 'g')
execute('%! clitrello list_cards ' . a:link . ' cards_markdown')
set filetype=markdown
endif
execute('redraw!')
endfunction
function! OpenTrelloHistory()
let a:line = getline('.')
silent ! pass foo/foo
if match(a:line, "^\* <[^>]*>") != -1
let a:link = substitute(a:line, '^\* <\([^>]*\)>.*$', '\1', 'g')
elseif match(a:line, "^# <[^>]*>") != -1
let a:link = substitute(a:line, '^# <\([^>]*\)>.*$', '\1', 'g')
execute('%! clitrello -f closed -l board_cards ' . a:link . ' cards_markdown')
elseif match(a:line, "^## <[^>]*>") != -1
let a:link = substitute(a:line, '^## <\([^>]*\)>.*$', '\1', 'g')
execute('%! clitrello -f closed -l list_cards ' . a:link . ' cards_markdown')
endif
set filetype=markdown
execute('redraw!')
endfunction
function! AddTrelloCard()
let a:line = getline('.')
if match(a:line, "^## <[^>]*>") != -1
let a:link = substitute(a:line, '^## <\([^>]*\)>.*$', '\1', 'g')
silent ! pass foo/foo
execute('silent !clear;clitrello add_card ' . a:link)
execute('redraw!')
endif
endfunction
function! ArchiveTrelloCard()
let a:line = getline('.')
if match(a:line, "^\* <[^>]*>") != -1
let a:link = substitute(a:line, '^\* <\([^>]*\)>.*$', '\1', 'g')
silent ! pass foo/foo
execute('silent !clear;clitrello archive_card ' . a:link)
execute('redraw!')
endif
endfunction
function! RenameTrelloCard()
let a:line = getline('.')
if match(a:line, "^\* <[^>]*>") != -1
let a:link = substitute(a:line, '^\* <\([^>]*\)>.*$', '\1', 'g')
let a:old_name = substitute(a:line, '^\* <\([^>]*\)>[^`]*`\([^`]*\)`$', '\2', 'g')
silent ! pass foo/foo
execute('silent !clear; old_name="' . a:old_name . '" clitrello rename_card ' . a:link)
execute('redraw!')
endif
endfunction
function! UpdateBuffer()
let a:line = getline(1)
if match(a:line, "^# <[^>]*>") != -1
let a:link = substitute(a:line, '^# <\([^>]*\)>.*$', '\1', 'g')
if a:link == "my_cards"
call ReadMyCards()
else
let save_pos = getpos(".")
" silent ! pass foo/foo
" execute('%! clitrello board_cards ' . a:link . ' cards_markdown')
" call setpos('.', save_pos)
" set filetype=markdown
" execute('redraw!')
" unlet save_pos
silent ! pass foo/foo
execute('redraw!')
call RunBackgroundCommand('clitrello board_cards ' . a:link . ' cards_markdown')
endif
endif
endfunction
function! ReadMyCards()
silent ! pass foo/foo
execute('redraw!')
call RunBackgroundCommand("clitrello cards cards_markdown")
endfunction
function! ReadMyUrgentCards()
silent ! pass foo/foo
execute('redraw!')
call RunBackgroundCommand("clitrello urgent")
endfunction
function! OpenTrelloAllBoards()
silent ! pass foo/foo
execute('%! clitrello boards boards_markdown')
set filetype=markdown
execute('redraw!')
endfunction
nnoremap <Leader>u :call UpdateBuffer()<CR>
nnoremap <Leader>e :call RenameTrelloCard()<CR>
nnoremap <Leader>c :call ArchiveTrelloCard()<CR>
nnoremap <Leader>a :call AddTrelloCard()<CR>
nnoremap <Leader>L :call OpenTrelloExternal()<CR>
nnoremap <Leader>l :call OpenTrello()<CR>
nnoremap <Leader>h :call OpenTrelloHistory()<CR>
nnoremap <Leader>K :call ReadMyUrgentCards()<CR>
nnoremap <Leader>k :call ReadMyCards()<CR>
nnoremap <Leader>m :call OpenTrelloAllBoards()<CR>
set filetype=markdown
if ! empty($custom_vimrc)
let g:custom_vimrc=$custom_vimrc
nnoremap <Leader>r :exec('source ' . g:custom_vimrc)<CR>
endif