summaryrefslogtreecommitdiff
path: root/plugin/bujo.vim
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/bujo.vim')
-rw-r--r--plugin/bujo.vim57
1 files changed, 48 insertions, 9 deletions
diff --git a/plugin/bujo.vim b/plugin/bujo.vim
index f29d268..e8b7077 100644
--- a/plugin/bujo.vim
+++ b/plugin/bujo.vim
@@ -1,21 +1,60 @@
1" bujo.vim - A minimalist todo list manager
2" Maintainer: Jersey Fonseca <http://www.jerseyfonseca.com/>
3" Version: 0.5
4
1"Make bujo directory if it doesn't exist" 5"Make bujo directory if it doesn't exist"
2let g:bujo#todo_file_path = get(g:, "bujo#todo_file_path", $HOME . "/.cache/bujo") 6let g:bujo#todo_file_path = get(g:, "bujo#todo_file_path", $HOME . "/.cache/bujo")
3if empty(glob(g:bujo#todo_file_path)) 7if empty(glob(g:bujo#todo_file_path))
4 call mkdir(g:bujo#todo_file_path) 8 call mkdir(g:bujo#todo_file_path)
5endif 9endif
6autocmd bufnewfile todo.md call append(0, '#Todo') 10
7autocmd bufnewfile todo.md call append(1, 'Date: ') 11" InGitRepository() tells us if the directory we are currently working in
8autocmd bufnewfile,bufread,filewritepre todo.md exe "g/Date: */s/Date: *.*/Date: " .strftime("%a %d %b %Y") 12" is a git repository. It makes use of the 'git rev-parse --is-inside-work-tree'
9autocmd bufnewfile,Bufwritepre,filewritepre todo.md execute "normal Go" 13" command. This command outputs true to the shell if so, and a STDERR message
14" otherwise.
15"
16" We will use this function to know whether we should open a specific
17" project's todo list, or a global todo list.
18function s:InGitRepository()
19 :silent let bool = system("git rev-parse --is-inside-work-tree")
20
21 " The git function will return true with some leading characters
22 " if we are in a repository. So, we split off those characters
23 " and just check the first word.
24 if split(bool, '\v\n')[0] == 'true'
25 return 1
26 endif
27endfunction
10 28
11 29
30" GetToplevelFolder() gives us a clean name of the git repository that we are
31" currently working in
32function s:GetToplevelFolder()
33 let absolute_path = system("git rev-parse --show-toplevel")
34 let repo_name = split(absolute_path, "/")
35 let repo_name_clean = split(repo_name[-1], '\v\n')[0]
36 return repo_name_clean
37endfunction
12 38
13" Open the bujo todo list file 39" OpenTodo() opens the respective todo.md file from $HOME/.cache/bujo
14function s:OpenTodo() 40" If we are in a git repository, we open the todo.md for that git repository.
15 "30 makes it open at width 30 41" Otherwise, we open the global todo file.
16 exe ":30vs" . g:bujo#todo_file_path . "/todo.md" 42function s:OpenTodo(...)
43 " If an argument was passed in, we open the general file
44 " a:0 will be false if no argument was passed in (a:0 == 0)
45 if a:0 || !s:InGitRepository()
46 exe ":30vs" . g:bujo#todo_file_path . "/todo.md"
47 else
48 let repo_name_clean = s:GetToplevelFolder()
49 exe ":30vs" . g:bujo#todo_file_path . "/" . repo_name_clean . "/todo.md"
50 endif
17endfunction 51endfunction
18 52
19if !exists(":Todo") 53if !exists(":Todo")
20 command Todo :call s:OpenTodo() 54 command -nargs=? Todo :call s:OpenTodo(<f-args>)
21endif 55endif
56
57autocmd bufnewfile todo.md call append(0, '#' . split(expand('%:p:h:t'), '\v\n')[0] . " todo")
58autocmd bufnewfile todo.md call append(1, 'Date: ')
59autocmd bufnewfile,bufread,filewritepre todo.md exe "g/Date: */s/Date: *.*/Date: " .strftime("%a %d %b %Y")
60autocmd bufnewfile,Bufwritepre,filewritepre todo.md execute "normal Go"