diff options
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/bujo.vim | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/plugin/bujo.vim b/plugin/bujo.vim index a2fa976..cdc5d53 100644 --- a/plugin/bujo.vim +++ b/plugin/bujo.vim | |||
@@ -2,8 +2,11 @@ | |||
2 | " Maintainer: Jersey Fonseca <http://www.jerseyfonseca.com/> | 2 | " Maintainer: Jersey Fonseca <http://www.jerseyfonseca.com/> |
3 | " Version: 0.5 | 3 | " Version: 0.5 |
4 | 4 | ||
5 | "Make bujo directory if it doesn't exist" | 5 | " Get custom configs |
6 | let g:bujo#todo_file_path = get(g:, "bujo#todo_file_path", $HOME . "/.cache/bujo") | 6 | let g:bujo#todo_file_path = get(g:, "bujo#todo_file_path", $HOME . "/.cache/bujo") |
7 | let g:bujo#window_width = get(g:, "bujo#window_width", 30) | ||
8 | |||
9 | " Make bujo directory if it doesn't exist" | ||
7 | if empty(glob(g:bujo#todo_file_path)) | 10 | if empty(glob(g:bujo#todo_file_path)) |
8 | call mkdir(g:bujo#todo_file_path) | 11 | call mkdir(g:bujo#todo_file_path) |
9 | endif | 12 | endif |
@@ -36,28 +39,48 @@ function s:GetToplevelFolder() | |||
36 | return repo_name_clean | 39 | return repo_name_clean |
37 | endfunction | 40 | endfunction |
38 | 41 | ||
39 | " OpenTodo() opens the respective todo.md file from $HOME/.cache/bujo | 42 | |
40 | " If we are in a git repository, we open the todo.md for that git repository. | 43 | " GetBujoFilePath() returns which file path we will be using. If we are in a |
41 | " Otherwise, we open the global todo file. | 44 | " git repository, we return the directory for that specific git repo. |
42 | function s:OpenTodo(...) | 45 | " Otherwise, we return the general file path. |
43 | " If an argument was passed in, we open the general file | 46 | " |
44 | " a:0 will be false if no argument was passed in (a:0 == 0) | 47 | " If we are passed an argument, it means that the user wants to open the |
45 | if a:0 || !s:InGitRepository() | 48 | " general bujo file, so we also return the general file path in that case |
46 | exe ":30vs" . g:bujo#todo_file_path . "/todo.md" | 49 | function s:GetBujoFilePath(general) |
47 | else | 50 | if a:general || !s:InGitRepository() |
48 | let repo_name_clean = s:GetToplevelFolder() | 51 | return g:bujo#todo_file_path . "/todo.md" |
49 | let todo_path = g:bujo#todo_file_path . "/" . repo_name_clean | 52 | else |
53 | let repo_name = s:GetToplevelFolder() | ||
54 | let todo_path = g:bujo#todo_file_path . "/" . repo_name | ||
50 | if empty(glob(todo_path)) | 55 | if empty(glob(todo_path)) |
51 | call mkdir(todo_path) | 56 | call mkdir(todo_path) |
52 | endif | 57 | endif |
53 | exe ":30vs" . todo_path . "/todo.md" | 58 | return todo_path . "/todo.md" |
54 | endif | 59 | endif |
55 | endfunction | 60 | endfunction |
56 | 61 | ||
62 | |||
63 | " OpenTodo() opens the respective todo.md file from $HOME/.cache/bujo | ||
64 | " If we are in a git repository, we open the todo.md for that git repository. | ||
65 | " Otherwise, we open the global todo file. | ||
66 | " | ||
67 | " Paramaters : | ||
68 | " | ||
69 | " mods - allows a user to use <mods> (see :h mods) | ||
70 | " | ||
71 | " ... - any parameter after calling :Todo will mean that the user wants | ||
72 | " us to open the general file path. We check this with a:0 | ||
73 | function s:OpenTodo(mods, ...) | ||
74 | let general_bool = a:0 | ||
75 | let todo_path = s:GetBujoFilePath(general_bool) | ||
76 | exe a:mods . " " . g:bujo#window_width "vs" . todo_path | ||
77 | endfunction | ||
78 | |||
57 | if !exists(":Todo") | 79 | if !exists(":Todo") |
58 | command -nargs=? Todo :call s:OpenTodo(<f-args>) | 80 | command -nargs=? Todo :call s:OpenTodo(<q-mods>, <f-args>) |
59 | endif | 81 | endif |
60 | 82 | ||
83 | " Update date upon enter. | ||
61 | autocmd bufnewfile todo.md call append(0, '#' . split(expand('%:p:h:t'), '\v\n')[0] . " todo") | 84 | autocmd bufnewfile todo.md call append(0, '#' . split(expand('%:p:h:t'), '\v\n')[0] . " todo") |
62 | autocmd bufnewfile todo.md call append(1, 'Date: ') | 85 | autocmd bufnewfile todo.md call append(1, 'Date: ') |
63 | autocmd bufnewfile,bufread,filewritepre todo.md exe "g/Date: */s/Date: *.*/Date: " .strftime("%a %d %b %Y") | 86 | autocmd bufnewfile,bufread,filewritepre todo.md exe "g/Date: */s/Date: *.*/Date: " .strftime("%a %d %b %Y") |