diff options
author | Jersey <fonseca@uchicago.edu> | 2020-06-26 19:03:53 +0000 |
---|---|---|
committer | Jersey <fonseca@uchicago.edu> | 2020-06-26 19:03:53 +0000 |
commit | e5786259c45ecf02158f13703cf191a429ce8b98 (patch) | |
tree | 95622e59e169ce979f93d9f340846eba4e25f3b5 /plugin | |
parent | df4d94af5f6a3434824cfd6cceaa58c56fb87877 (diff) |
Project specific integration
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/bujo.vim | 53 |
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 | |||
3 | if empty(glob(g:bujo#todo_file_path)) | 3 | if empty(glob(g:bujo#todo_file_path)) |
4 | call mkdir(g:bujo#todo_file_path) | 4 | call mkdir(g:bujo#todo_file_path) |
5 | endif | 5 | endif |
6 | autocmd bufnewfile todo.md call append(0, '#Todo') | ||
7 | autocmd bufnewfile todo.md call append(1, 'Date: ') | ||
8 | autocmd bufnewfile,bufread,filewritepre todo.md exe "g/Date: */s/Date: *.*/Date: " .strftime("%a %d %b %Y") | ||
9 | autocmd 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. | ||
14 | function 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 | ||
23 | endfunction | ||
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 |
14 | function s:OpenTodo() | 27 | " currently working in |
15 | "30 makes it open at width 30 | 28 | function 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 | ||
33 | endfunction | ||
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. | ||
38 | function 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 | ||
17 | endfunction | 47 | endfunction |
18 | 48 | ||
19 | if !exists(":Todo") | 49 | if !exists(":Todo") |
20 | command Todo :call s:OpenTodo() | 50 | command -nargs=? Todo :call s:OpenTodo(<f-args>) |
21 | endif | 51 | endif |
52 | |||
53 | autocmd bufnewfile todo.md call append(0, '#' . split(expand('%:p:h:t'), '\v\n')[0] . " todo") | ||
54 | autocmd bufnewfile todo.md call append(1, 'Date: ') | ||
55 | autocmd bufnewfile,bufread,filewritepre todo.md exe "g/Date: */s/Date: *.*/Date: " .strftime("%a %d %b %Y") | ||
56 | autocmd bufnewfile,Bufwritepre,filewritepre todo.md execute "normal Go" | ||