From 46af9f393c9e7044ec66ec7cafdf8370d186d3e5 Mon Sep 17 00:00:00 2001 From: Jersey Date: Tue, 30 Jun 2020 10:54:00 -0500 Subject: adding branch --- plugin/bujo.vim | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'plugin') diff --git a/plugin/bujo.vim b/plugin/bujo.vim index a2fa976..b905b3a 100644 --- a/plugin/bujo.vim +++ b/plugin/bujo.vim @@ -2,8 +2,11 @@ " Maintainer: Jersey Fonseca " Version: 0.5 -"Make bujo directory if it doesn't exist" +" Get custom configs let g:bujo#todo_file_path = get(g:, "bujo#todo_file_path", $HOME . "/.cache/bujo") +let g:bujo#window_width = get(g: "bujo#window_width", 30) + +" Make bujo directory if it doesn't exist" if empty(glob(g:bujo#todo_file_path)) call mkdir(g:bujo#todo_file_path) endif @@ -43,14 +46,14 @@ function s:OpenTodo(...) " If an argument was passed in, we open the general file " a:0 will be false if no argument was passed in (a:0 == 0) if a:0 || !s:InGitRepository() - exe ":30vs" . g:bujo#todo_file_path . "/todo.md" + exe ":" . g:bujo#window_width . "vs" . g:bujo#todo_file_path . "/todo.md" else let repo_name_clean = s:GetToplevelFolder() let todo_path = g:bujo#todo_file_path . "/" . repo_name_clean if empty(glob(todo_path)) call mkdir(todo_path) endif - exe ":30vs" . todo_path . "/todo.md" + exe ":" . g:bujo#window_width "vs" . todo_path . "/todo.md" endif endfunction @@ -58,6 +61,7 @@ if !exists(":Todo") command -nargs=? Todo :call s:OpenTodo() endif +" Update date upon enter. autocmd bufnewfile todo.md call append(0, '#' . split(expand('%:p:h:t'), '\v\n')[0] . " todo") autocmd bufnewfile todo.md call append(1, 'Date: ') autocmd bufnewfile,bufread,filewritepre todo.md exe "g/Date: */s/Date: *.*/Date: " .strftime("%a %d %b %Y") -- cgit v1.2.3 From 8e54b608cb0d1058bd34f475c3ae7c69111e3520 Mon Sep 17 00:00:00 2001 From: Jersey Date: Tue, 30 Jun 2020 11:42:46 -0500 Subject: Added mods and custom width config --- plugin/bujo.vim | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'plugin') diff --git a/plugin/bujo.vim b/plugin/bujo.vim index b905b3a..cdc5d53 100644 --- a/plugin/bujo.vim +++ b/plugin/bujo.vim @@ -4,7 +4,7 @@ " Get custom configs let g:bujo#todo_file_path = get(g:, "bujo#todo_file_path", $HOME . "/.cache/bujo") -let g:bujo#window_width = get(g: "bujo#window_width", 30) +let g:bujo#window_width = get(g:, "bujo#window_width", 30) " Make bujo directory if it doesn't exist" if empty(glob(g:bujo#todo_file_path)) @@ -39,26 +39,45 @@ function s:GetToplevelFolder() return repo_name_clean endfunction -" OpenTodo() opens the respective todo.md file from $HOME/.cache/bujo -" If we are in a git repository, we open the todo.md for that git repository. -" Otherwise, we open the global todo file. -function s:OpenTodo(...) - " If an argument was passed in, we open the general file - " a:0 will be false if no argument was passed in (a:0 == 0) - if a:0 || !s:InGitRepository() - exe ":" . g:bujo#window_width . "vs" . g:bujo#todo_file_path . "/todo.md" - else - let repo_name_clean = s:GetToplevelFolder() - let todo_path = g:bujo#todo_file_path . "/" . repo_name_clean + +" GetBujoFilePath() returns which file path we will be using. If we are in a +" git repository, we return the directory for that specific git repo. +" Otherwise, we return the general file path. +" +" If we are passed an argument, it means that the user wants to open the +" general bujo file, so we also return the general file path in that case +function s:GetBujoFilePath(general) + if a:general || !s:InGitRepository() + return g:bujo#todo_file_path . "/todo.md" + else + let repo_name = s:GetToplevelFolder() + let todo_path = g:bujo#todo_file_path . "/" . repo_name if empty(glob(todo_path)) call mkdir(todo_path) endif - exe ":" . g:bujo#window_width "vs" . todo_path . "/todo.md" + return todo_path . "/todo.md" endif endfunction + +" OpenTodo() opens the respective todo.md file from $HOME/.cache/bujo +" If we are in a git repository, we open the todo.md for that git repository. +" Otherwise, we open the global todo file. +" +" Paramaters : +" +" mods - allows a user to use (see :h mods) +" +" ... - any parameter after calling :Todo will mean that the user wants +" us to open the general file path. We check this with a:0 +function s:OpenTodo(mods, ...) + let general_bool = a:0 + let todo_path = s:GetBujoFilePath(general_bool) + exe a:mods . " " . g:bujo#window_width "vs" . todo_path +endfunction + if !exists(":Todo") - command -nargs=? Todo :call s:OpenTodo() + command -nargs=? Todo :call s:OpenTodo(, ) endif " Update date upon enter. -- cgit v1.2.3