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