Update 2024-02-14 16:20 Linux/x86_64-ld5587

This commit is contained in:
c0dev0id
2024-02-14 16:20:07 +01:00
parent 35ed2c3d92
commit 8d78a17efb
19 changed files with 2058 additions and 0 deletions

View File

@@ -0,0 +1,370 @@
function! taskwarrior#action#new()
call taskwarrior#system_call('', 'add', taskwarrior#data#get_args('add'), 'echo')
endfunction
function! taskwarrior#action#set_done()
call taskwarrior#system_call(taskwarrior#data#get_uuid(), ' done', '', 'silent')
endfunction
function! taskwarrior#action#urgency() abort
let cc = taskwarrior#data#current_column()
let udas = split(system('task _udas'), '\n')
let cmap = { 'start' : 'active',
\ 'entry' : 'age',
\ 'depends' : 'blocked',
\ 'parent' : 'blocking',
\ 'wait' : 'waiting',
\ 'description' : 'annotations'
\ }
let isuda = 0
if has_key(cmap, cc)
let cc = cmap[cc]
elseif index(['due', 'priority', 'project', 'tags', 'scheduled']
\ , cc) == -1
if index(udas, cc) == -1
call taskwarrior#sort#by_arg('urgency-')
return
else
let isuda = 1
endif
endif
let rcfile = $HOME.'/.taskrc'
if filereadable(rcfile)
let cv = taskwarrior#data#get_value_by_column(line('.'), cc)
let option = isuda ? 'urgency.uda.'.cc.'.coefficient' :
\ 'urgency.'.cc.'.coefficient'
if len(cv)
let ctag = expand('<cword>')
if cc == 'tags' && index(split(cv), ctag) != -1
let option = 'urgency.user.tag.'.ctag.'.coefficient'
elseif cc == 'project' && cv =~ '^[^ \t%\\*]\+$'
let pl = split(cv, '\.')
let idx = index(pl, expand('<cword>'))
let option = 'urgency.user.project.'.
\ join(pl[0:idx], '.').'.coefficient'
elseif isuda && cv =~ '^\w\+$'
let option = 'urgency.uda.'.cc.'.'.cv.'.coefficient'
endif
endif
let default_raw = split(system('task _get rc.'.option), '\n')
let default = len(default_raw) ? default_raw[0] : '0'
let new = input(option.' : ', default)
let lines = readfile(rcfile)
let index = match(lines, option)
if str2float(new) == str2float(default)
elseif str2float(new) == 0
call filter(lines, 'v:val !~ option')
elseif index == -1
call add(lines, option.'='.new)
else
let lines[index] = option.'='.new
endif
call writefile(lines, rcfile)
endif
call taskwarrior#sort#by_arg('urgency-')
execute 'normal! :\<Esc>'
endfunction
function! taskwarrior#action#modify(mode)
let uuid = taskwarrior#data#get_uuid()
if uuid == ''
return
endif
if a:mode == 'current'
let field = taskwarrior#data#current_column()
if index(['id', 'uuid', 'status', 'urgency'], field) != -1
return
elseif field == 'description'
call taskwarrior#system_call(uuid, 'modify', taskwarrior#data#get_args('modify', [field]), 'external')
else
call taskwarrior#system_call(uuid, 'modify', taskwarrior#data#get_args('modify', [field]), 'silent')
endif
else
call taskwarrior#system_call(uuid, 'modify', taskwarrior#data#get_args('modify'), 'external')
endif
endfunction
function! taskwarrior#action#delete()
let uuid = taskwarrior#data#get_uuid()
if uuid == ''
call taskwarrior#action#annotate('del')
else
let ccol = taskwarrior#data#current_column()
if index(['project', 'tags', 'due', 'priority', 'start', 'depends'], ccol) != -1
call taskwarrior#system_call(uuid, 'modify', ccol.':', 'silent')
else
execute '!task '.uuid.' delete'
endif
endif
call taskwarrior#refresh()
endfunction
function! taskwarrior#action#remove()
execute '!task '.taskwarrior#data#get_uuid().' delete'
call taskwarrior#list()
endfunction
function! taskwarrior#action#annotate(op)
let ln = line('.')
let offset = -1
while ln > 1 && taskwarrior#data#get_uuid(ln) == ''
let ln -= 1
let offset += 1
endwhile
let uuid = taskwarrior#data#get_uuid(ln)
if uuid == ''
return
endif
if a:op == 'add'
let annotation = input('new annotation:', '', 'file')
call taskwarrior#system_call(uuid, ' annotate ', annotation, 'silent')
elseif a:op == 'del'
let annotation = input('annotation pattern to delete:')
call taskwarrior#system_call(uuid, ' denotate ', annotation, 'silent')
elseif offset >= 0
let taskobj = taskwarrior#data#get_query(uuid)
if exists('taskobj.annotations[offset].description')
let file = substitute(taskobj.annotations[offset].description, '\s*\/\s*', '/', 'g')
let file = escape(file, ' ')
let ft = 'text'
if executable('file')
let ft = system('file '.file)[:-2]
endif
if ft =~ 'text$'
execute 'e '.file
elseif ft !~ '(No such file or directory)' || file =~ '[a-z]*:\/\/[^ >,;]*'
if executable('xdg-open')
call system('xdg-open '.file.'&')
elseif executable('open')
call system('open '.file.'&')
endif
endif
endif
endif
endfunction
function! taskwarrior#action#filter()
let column = taskwarrior#data#current_column()
if index(['project', 'tags', 'status', 'priority'], column) != -1 && line('.') > 1
let filter = substitute(substitute(taskwarrior#data#get_args('modify', [column]), 'tags:', '+', ''), '\v^\s*\+(\s|$)', '', '')
elseif column =~ '\v^(entry|end|due)$'
let filter = column.'.before:'.input(column.'.before:', taskwarrior#data#get_value_by_column('.', column))
elseif column == 'description'
let filter = 'description:'.input('description:', taskwarrior#data#get_value_by_column('.', column) )
else
let filter = input('new filter:', b:filter, 'customlist,taskwarrior#complete#filter')
endif
let filter = substitute(filter, 'status:\(\s\|$\)', 'status.any: ', 'g')
if filter != b:filter
let b:filter = filter
let b:hist = 1
call taskwarrior#list()
endif
endfunction
function! taskwarrior#action#command()
if len(b:selected) == 0
let filter = taskwarrior#data#get_uuid()
else
let filter = join(b:selected, ',')
endif
let command = input('task '.filter.':', '', 'customlist,taskwarrior#complete#command')
if index(g:task_all_commands, b:command) == -1
return
endif
call taskwarrior#system_call(filter, command, '', 'interactive')
endfunction
function! taskwarrior#action#report()
let command = input('new report:', g:task_report_name, 'customlist,taskwarrior#complete#report')
if index(g:task_report_command, command) != -1 && command != b:command
let b:command = command
let b:hist = 1
call taskwarrior#list()
endif
endfunction
function! taskwarrior#action#paste()
if len(b:selected) == 0
return
elseif len(b:selected) < 3
call taskwarrior#system_call(join(b:selected, ','), 'duplicate', '', 'echo')
else
call taskwarrior#system_call(join(b:selected, ','), 'duplicate', '', 'interactive')
endif
endfunction
function! taskwarrior#action#columns_format_change(direction)
let ccol = taskwarrior#data#current_column()
if !exists('g:task_columns_format[ccol]')
return
endif
let clist = g:task_columns_format[ccol]
if len(clist) == 1
return
endif
let ccol_ful = b:task_report_columns[taskwarrior#data#current_index()]
let ccol_sub = matchstr(ccol_ful, '\.\zs.*')
let rcl = matchstr(b:rc, 'rc\.report\.'.b:command.'\.columns.\zs\S*')
" let dfl = system('task _get -- rc.report.'.b:command.'.columns')[0:-2]
let dfl = matchstr(system('task show | grep report.'.b:command.'.columns')[0:-2], '\S*$')
let index = index(clist, ccol_sub)
let index = index == -1 ? 0 : index
if a:direction == 'left'
let index -= 1
else
let index += 1
if index == len(clist)
let index = 0
endif
endif
let newsub = index == 0 ? '' : '.'.clist[index]
let b:rc .= ' rc.report.'.b:command.'.columns:'.
\ substitute(
\ rcl == '' ? dfl : rcl,
\ '[=:,]\zs'.ccol_ful.'\ze\(,\|$\)',
\ ccol.newsub, ''
\ )
let b:hist = 1
call taskwarrior#list()
endfunction
function! taskwarrior#action#date(count)
let ccol = taskwarrior#data#current_column()
if index(['due', 'end', 'entry'], ccol) == -1
return
endif
setlocal modifiable
if exists('g:loaded_speeddating')
call speeddating#increment(a:count)
elseif a:count > 0
execute 'normal! '.a:count.''
else
execute 'normal! '.-a:count.''
endif
let b:ct = taskwarrior#data#get_uuid()
call taskwarrior#system_call(b:ct, 'modify', ccol.':'.taskwarrior#data#get_value_by_column('.', ccol, 'temp'), 'silent')
endfunction
function! taskwarrior#action#visual(action) range
let line1 = getpos("'<")[1]
let line2 = getpos("'>")[1]
let fil = []
let lin = []
for l in range(line1, line2)
let uuid = taskwarrior#data#get_uuid(l)
if uuid !~ '^\s*$'
let fil += [uuid]
let lin += [l]
endif
endfor
let filter = join(fil, ',')
if a:action == 'done'
call taskwarrior#system_call(filter, 'done', '', 'interactive')
elseif a:action == 'delete'
call taskwarrior#system_call(filter, 'delete', '', 'interactive')
elseif a:action == 'info'
call taskinfo#init('information', filter, split(system('task rc.color=no information '.filter), '\n'))
elseif a:action == 'select'
for var in fil
let index = index(b:selected, var)
if index == -1
let b:selected += [var]
let b:sline += [lin[index(fil, var)]]
else
call remove(b:selected, index)
call remove(b:sline, index)
endif
endfor
let b:sstring = join(b:selected, ' ')
setlocal syntax=taskreport
endif
endfunction
function! taskwarrior#action#move_cursor(direction, mode)
let ci = taskwarrior#data#current_index()
if ci == -1 || (ci == 0 && a:direction == 'left') || (ci == len(b:task_columns)-1 && a:direction == 'right')
return
endif
if a:direction == 'left'
call search('\%'.(b:task_columns[ci-1]+1).'v', 'be')
else
call search('\%'.(b:task_columns[ci+1]+1).'v', 'e')
endif
if a:mode == 'skip' && taskwarrior#data#get_value_by_index('.', taskwarrior#data#current_index()) =~ '^\s*$'
call taskwarrior#action#move_cursor(a:direction, 'skip')
endif
endfunction
function! taskwarrior#action#undo()
if has("gui_running")
if exists('g:task_gui_term') && g:task_gui_term == 1
!task rc.color=off undo
elseif executable('xterm')
silent !xterm -e 'task undo'
elseif executable('urxvt')
silent !urxvt -e task undo
elseif executable('gnome-terminal')
silent !gnome-terminal -e 'task undo'
endif
else
sil !clear
!task undo
endif
call taskwarrior#refresh()
endfunction
function! taskwarrior#action#clear_completed()
!task status:completed delete
call taskwarrior#refresh()
endfunction
function! taskwarrior#action#sync(action)
execute '!task '.a:action.' '
call taskwarrior#refresh()
endfunction
function! taskwarrior#action#select()
let uuid = taskwarrior#data#get_uuid()
if uuid == ''
return
endif
let index = index(b:selected, uuid)
if index == -1
let b:selected += [uuid]
let b:sline += [line('.')]
else
call remove(b:selected, index)
call remove(b:sline, index)
endif
let b:sstring = join(b:selected, ' ')
setlocal syntax=taskreport
endfunction
function! taskwarrior#action#show_info(...)
if a:0 > 0
let command = 'info'
let filter = a:1
else
let ccol = taskwarrior#data#current_column()
let dict = { 'project': 'projects',
\ 'tags': 'tags',
\ 'id': 'stats',
\ 'depends': 'blocking',
\ 'recur': 'recurring',
\ 'due': 'overdue',
\ 'wait': 'waiting',
\ 'urgency': 'ready',
\ 'entry': 'history.monthly',
\ 'end': 'history.monthly'}
let command = get(dict, ccol, 'summary')
let uuid = taskwarrior#data#get_uuid()
if uuid !~ '^\s*$'
let command = substitute(command, '\v(summary|stats)', 'information', '')
let filter = taskwarrior#data#get_uuid()
else
let filter = b:filter
endif
endif
call taskinfo#init(command, filter, split(system('task rc.color=no '.command.' '.filter), '\n'))
endfunction

View File

@@ -0,0 +1,54 @@
function! taskwarrior#complete#TW(A, L, P)
let command = copy(g:task_all_commands)
let filter = copy(g:task_filter)
let config = copy(g:task_all_configurations)
let contexts = split(system('task _context'), '\n')
let context_cmd = ['define', 'show', 'list', 'delete']
let words = split(a:L, ' ')
if len(words) > 1 && words[1] == 'context'
if len(words) == 2 || index(context_cmd, words[2]) == -1
return filter(context_cmd + contexts + ['none'],
\ 'match(v:val, a:A) != -1')
elseif words[2] == 'delete'
return filter(contexts, 'match(v:val, a:A) != -1')
else
return []
endif
endif
for ph in words
if ph == 'config' || ph == 'show'
return filter(config, 'match(v:val, a:A) != -1')
elseif ph =~ '^rc\..*'
return map(filter(config, 'match(v:val, a:A[3:]) != -1'),
\ "'rc.'.v:val")
elseif index(command, ph) != -1
return filter(filter, 'match(v:val, a:A) != -1')
endif
endfor
return filter(command+filter, 'match(v:val, a:A) != -1')
endfunction
function! taskwarrior#complete#sort(A, L, P)
let cols = map(split(system('task _columns'), '\n'),
\ 'matchstr(v:val, "^\\w*")')
return filter(cols, 'match(v:val, a:A) != -1')
endfunction
function! taskwarrior#complete#filter(A, L, P)
let lead = matchstr(a:A, '\S*$')
let lead = lead == '' ? '.*' : lead
let dict = copy(g:task_filter)
for ph in split(a:L, ' ')
call remove(dict, index(dict, matchstr(ph, '.*:\ze')))
endfor
return map(filter(dict, 'match(v:val, lead) != -1'),
\ "matchstr(a:L, '.*\\ze\\s\\+\\S*').' '.v:val")
endfunction
function! taskwarrior#complete#command(A, L, P)
return filter(copy(g:task_all_commands), 'match(v:val, a:A) != -1')
endfunction
function! taskwarrior#complete#report(A, L, P)
return filter(copy(g:task_report_command), 'match(v:val, a:A) != -1')
endfunction

View File

@@ -0,0 +1,132 @@
function! taskwarrior#data#get_uuid(...)
let line = a:0 == 0 ? '.' : a:1
let vol = taskwarrior#data#get_value_by_column(line, 'uuid')
let vol = vol =~ '[0-9a-f]\{8}\(-[0-9a-f]\{4}\)\{3}-[0-9a-f]\{12}' ?
\ vol : taskwarrior#data#get_value_by_column(line, 'id')
return vol =~ '^\s*-*\s*$' ? '' : vol
endfunction
function! taskwarrior#data#get_args(...)
if a:0 == 0
return
elseif a:0 == 1
return taskwarrior#data#get_args(a:1, g:task_default_prompt)
endif
let arg = ' '
for key in a:2
let default = a:1 == 'modify' ?
\ taskwarrior#data#get_value_by_column('.', key)
\ : ''
let temp = shellescape(input(key.":", default), 1)
if key == 'description'
let arg .= ' '.temp
elseif temp !~ '^[ \t]*$' || a:1 == 'modify'
let arg .= ' '.key.':'.temp
endif
endfor
echom arg
return arg
endfunction
function! taskwarrior#data#get_value_by_column(line, column, ...)
if a:line == 1 || (a:line == '.' && line('.') == 1)
return ''
endif
if a:column == 'id' || a:column == 'uuid' || exists('a:1')
let index = match(b:task_report_columns, '^'.a:column.'.*')
return taskwarrior#data#get_value_by_index(a:line, index(b:task_report_columns, a:column))
else
let dict = taskwarrior#data#get_query()
let val = get(dict, a:column, '')
if type(val) == type('')
return val
elseif type(val) == type([])
return join(val, ' ')
else
return string(val)
endif
endif
endfunction
function! taskwarrior#data#get_value_by_index(line, index)
if exists('b:task_columns[a:index]')
return substitute(getline(a:line)[b:task_columns[a:index]:b:task_columns[a:index+1]-1], '\(\s*$\|^\s*\)', '', 'g')
endif
return ''
endfunction
function! taskwarrior#data#current_index()
let i = 0
while i < len(b:task_columns) && virtcol('.') >= b:task_columns[i]
let i += 1
endwhile
return i-1
endfunction
function! taskwarrior#data#current_column()
return matchstr(b:task_report_columns[taskwarrior#data#current_index()], '^\w\+')
endfunction
function! taskwarrior#data#get_stats(method)
let dict = {}
if a:method != 'current'
let stat = split(system('task '.a:method.' stats'), '\n')
else
let uuid = taskwarrior#data#get_uuid()
let stat = split(system('task '.taskwarrior#data#get_uuid().' stats'), '\n')
if uuid == '' || len(stat) < 5
return {}
endif
endif
for line in stat[2:-1]
if line !~ '^\W*$'
let dict[split(line, '\s\s')[0]] = substitute(split(line, '\s\s')[-1], '^\s*', '', '')
endif
endfor
return dict
endfunction
function! taskwarrior#data#get_query(...)
let uuid = get(a:, 1, taskwarrior#data#get_uuid())
if uuid == ''
return {}
endif
let obj = webapi#json#decode(substitute(system(
\ 'task rc.verbose=off '.uuid.' export'),
\ '\nConfiguration.*', '', ''))
return type(obj) == 3 ? obj[0] : obj
endfunction
function! taskwarrior#data#global_stats()
let dict = taskwarrior#data#get_stats(b:filter)
return [
\ get(dict, 'Pending', 0),
\ get(dict, 'Completed', 0),
\ get(taskwarrior#data#get_stats(''), 'Pending', 0)
\ ]
endfunction
function! taskwarrior#data#category()
let dict = {}
let dict.Pending = []
let dict.Waiting = []
let dict.Recurring = []
let dict.Completed = []
for i in range(2, line('$'))
let uuid = taskwarrior#data#get_uuid(i)
if uuid == ''
continue
endif
let subdict = taskwarrior#data#get_stats(uuid)
if subdict.Pending == '1'
let dict.Pending += [i]
elseif subdict.Waiting == '1'
let dict.Waiting += [i]
elseif subdict.Recurring == '1'
let dict.Recurring += [i]
elseif subdict.Completed == '1'
let dict.Completed += [i]
endif
endfor
return dict
endfunction

View File

@@ -0,0 +1,68 @@
if !isdirectory(expand(g:task_log_directory))
call mkdir(expand(g:task_log_directory), 'p')
endif
let s:history_file = expand(g:task_log_directory.'/.vim_tw.history')
let s:bookmark_file = expand(g:task_log_directory.'/.vim_tw.bookmark')
function! taskwarrior#log#history(action)
if findfile(s:history_file) == ''
call writefile([], s:history_file)
endif
if a:action == 'write' && filewritable(s:history_file) && b:hist == 1
let fl = readfile(s:history_file)
let numb = len(fl)
let last = numb ? substitute(fl[-1], '\v($|\n|\t|\s)', '', 'g') : ''
let current = join([b:command, b:filter, b:rc], ' ')
if last == substitute(current, '[\t ]', '', 'g')
return
endif
call add(fl, current)
if numb >= g:task_log_max
call remove(fl, 0)
endif
call writefile(fl, s:history_file)
elseif a:action == 'read' && filereadable(s:history_file)
call taskwarrior#init(join(split(readfile(s:history_file)[-1], ' '), ' '))
elseif a:action == 'clear'
call writefile([], s:history_file)
elseif a:action != 'write'
let hists = readfile(s:history_file)
if a:action == 'previous'
if b:hist >= len(hists)
return
endif
let b:hist += 1
elseif a:action == 'next'
if b:hist == 1
return
endif
let b:hist -= 1
endif
let hlist = split(substitute(hists[-b:hist], '\v($|\n)', ' ', ''), ' ')
if len(hlist) != 3
return
endif
let [b:command, b:filter, b:rc] = hlist
call taskwarrior#list()
endif
endfunction
function! taskwarrior#log#bookmark(action)
if findfile(s:bookmark_file) == ''
call writefile([], s:bookmark_file)
endif
if a:action == 'new' && filewritable(s:bookmark_file)
let now = b:command.' '.b:filter.' '.b:rc
let ext = readfile(s:bookmark_file)
if index(ext, now) == -1
execute 'redir >> '.s:bookmark_file
silent! echo now
redir END
echohl String
echomsg 'New bookmark added.'
echohl None
endif
elseif a:action == 'clear'
call writefile([], s:bookmark_file)
endif
endfunction

View File

@@ -0,0 +1,88 @@
function! taskwarrior#sort#by_arg(...)
let args = substitute(join(a:000, ' '), '\s\+', ',', 'g')
let args = substitute(args, '\w\zs,', '-,', 'g')
let args = substitute(args, '\w\zs$', '-', '')
if args =~ '^\s*$'
let b:rc = substitute(b:rc, 'rc.report.'.b:command.'.sort[:=]\S*', '', 'g')
else
let b:rc .= args == '' ? '' : ' rc.report.'.b:command.'.sort:'.args
endif
let b:hist = 1
call taskwarrior#list()
endfunction
function! taskwarrior#sort#by_column(polarity, column)
let fromrc = matchstr(b:rc, 'rc\.report\.'.b:command.'\.sort.\zs\S*')
" let default = system('task _get -- rc.report.'.b:command.'.sort')[0:-2]
let default = matchstr(system('task show | grep report.'.b:command.'.sort')[0:-2], '\S*$')
let colshort = map(copy(b:task_report_columns), 'matchstr(v:val, "^\\w*")')
let ccol = index(colshort, a:column) == -1 ?
\ taskwarrior#data#current_column() :
\ a:column
let list = split(fromrc, ',')
let ind = index(split(fromrc, '[-+],\='), ccol)
let dlist = split(default, ',')
let dind = index(split(default, '[-+],\='), ccol)
if fromrc == ''
if dind != -1
if a:polarity == 'm'
if dind == 0
let dlist[0] = dlist[0][0:-2].(dlist[0][-1:-1] == '+' ? '-' : '+')
endif
call insert(dlist, remove(dlist, dind))
elseif dlist[dind] == ccol.a:polarity
return
else
let dlist[dind] = ccol.a:polarity
endif
let b:rc .= ' rc.report.'.b:command.'.sort:'.join(dlist, ',')
else
let polarity = a:polarity == 'm' ? '-' : a:polarity
let b:rc .= ' rc.report.'.b:command.'.sort:'.ccol.polarity.','.default
endif
elseif ind != -1
if a:polarity == 'm'
if ind == 0
let list[0] = list[0][0:-2].(list[0][-1:-1] == '+' ? '-' : '+')
else
call insert(list, remove(list, ind))
endif
elseif list[ind] == ccol.a:polarity
if a:polarity == '+'
call insert(list, remove(list, ind), ind > 1 ? ind-1 : 0)
else
if ind > len(list)-3
call add(list, remove(list, ind))
else
call insert(list, remove(list, ind), ind+1)
endif
endif
else
let list[ind] = ccol.a:polarity
endif
let g:listabc = list
let b:rc = substitute(b:rc, 'report\.'.b:command.'\.sort.'.fromrc, 'report.'.b:command.'.sort:'.join(list, ','), '')
else
let polarity = a:polarity == 'm' ? '-' : a:polarity
let b:rc = substitute(b:rc, 'report\.'.b:command.'\.sort.', 'report.'.b:command.'.sort:'.ccol.polarity.',', '')
endif
let b:hist = 1
call taskwarrior#list()
endfunction
function! taskwarrior#sort#order_list()
let fromrc = matchstr(b:rc, 'rc\.report\.'.b:command.'\.sort.\zs\S*')
if fromrc == ''
" let list = split(system('task _get -- rc.report.'.b:command.'.sort')[0:-2], ',')
let list = split(matchstr(system('task show | grep report.'.b:command.'.sort')[0:-2], '\S*$'), ',')
else
let list = split(fromrc, ',')
endif
while exists('list[0]') && match(b:task_report_columns, list[0][0:-2]) == -1 && system('task count '.list[0][0:-2].'.any:')[0] == '0'
call remove(list, 0)
endwhile
if len(list) == 0
let list = ['status-']
endif
return list
endfunction