├── README.md ├── doc └── BulletColor.PNG ├── init.sh ├── setup.sh └── vim_log /README.md: -------------------------------------------------------------------------------- 1 | # Bashlog 2 | 3 | A simple, directory-driven logging utility for CLI for quick notes, long journals, or bullet-style todo lists. 4 | 5 | Works in bash with vim. But you can easily extend the idea to ther environments 6 | 7 | # Setup 8 | 9 | 1. Get the repo: 10 | 11 | `git clone git@github.com:jodavaho/bashlog.git ~/.config/bashlog` 12 | 13 | 2. Add some magic to your `~/.bashrc`: 14 | 15 | ``` 16 | source ~/.config/bashlog/bashlog.sh 17 | ``` 18 | 19 | From anywhere on your machine, just type `log`, to be taken to a date-stamped file that contains whatever you need to record. 20 | 21 | # Easy intro 22 | 23 | Need to keep track of something you just thought of? 24 | 25 | Just type `log` and you'll have a terminal with all of today's notes that were stored in the specified directory. 26 | 27 | What did you write yesterday? `log yesterday`. Easy peasy. Same for tomorrow, a month from now (`log 1 month`), last week `log last week` etc etc. Bashlog uses `date` and sometimes `dateutils`, so it gets a lot of flexibility. 28 | 29 | # Todo lists 30 | 31 | While logging, just use the handy bullet-style todo items: 32 | 33 | ``` 34 | - [ ] An unfinished todo item (github markdown compatible!) 35 | - [x] A successfully finished item 36 | - [-] A failed, but finished item 37 | - [>] A delayed item 38 | - [v] A dropped item, no longer required 39 | ``` 40 | 41 | To spice it up a bit, I added the color-highlights in `vim_log`, and they are added by default when you type `log`. 42 | 43 | (otherwise, Just add to your .bashrc: `export LOG_EDITOR='vim -S vim_log'`) 44 | 45 | Or, just add it to .vimrc forever if you really like it. 46 | 47 | ``` 48 | cat vim_log >> ~/.vimrc 49 | ``` 50 | 51 | See image: 52 | 53 | ![bulletColor](doc/BulletColor.PNG) 54 | 55 | ## Getting todo items on CLI 56 | 57 | To see the todo items in your directory, use `lstodo`. 58 | 59 | I usually do this: 60 | 61 | `lstodo -nl | vim -` to get a jump-list for VIM. 62 | 63 | My daily morning ritual to prioritize is to scroll through list, using `gF` to jump to the todo item, mark it, and `b#` jump back. Vimrc settings to help with this are `set autowrite` 64 | 65 | ## Weekly 66 | 67 | However, for most todos, I set weekly goals. For this, I use `week`. 68 | This creates files like `2019-week-X` where `X` is the current week. Ticking off weekly goals leading up to the weekend is *quite* rewarding. 69 | 70 | You can view last week with `week -1` or next week with `week +1`, or arbitrarily `week +/-X` to jump around. 71 | 72 | 73 | # Log tips 74 | 75 | the `log` command uses `date` and `dateutils` to form the filename. SO you can do nifty things like: 76 | 77 | - `log tomorrow` 78 | - `log yesterday` 79 | - `log last monday` 80 | - `log 1 month` 81 | 82 | etc 83 | 84 | ## Journaling 85 | 86 | I like to write my daily thoughts (e.g., journal), using `log` and re-read yesterday / the before by using `log yesterday` and `log last wed` for example. 87 | 88 | I've been using this system for almost a decade. As of the time of this commit ... 89 | 90 | ``` 91 | :~/journal$ ls -l | wc -l 92 | 1461 93 | :~/journal$ cat * | wc 94 | 33948 298680 1642722 95 | ``` 96 | 97 | Reading journal entries from when my wife and I started dating is a real treat. 98 | My health has been easy to track. I have a greppable archive of my hourly 99 | thoughts in plain text. I've given real thought to applying some analytics to 100 | this dataset, including sentiment analysis. Though I go on and off with the 101 | habit of journalling, lowering the barrier of adding an entry has significantly 102 | helped. 103 | 104 | ## Different log directories. 105 | 106 | Sometimes I change projects. e.g., when moving between python environments, catkin workspaces, etc. In the `setup.sh` or `activate.sh`, I like to add: 107 | 108 | ``` 109 | export LOG_DIRECTORY /notes 110 | ``` 111 | 112 | This means that for each project, you will definitely have a consistent set of notes and todos, which will not overlap. 113 | 114 | ## Base workspace 115 | 116 | For things like journalling, I also `alias home='export LOG_DIRECTORY=~/journal'` 117 | 118 | ## Git integration 119 | 120 | I don't recommend this for all logs, but to remove all possible workflow barriers, I have a convenience vim command so that I can keep my logs in github easily. 121 | 122 | `command Lw w | !git add % && git commit % -m "Checkin %" && git push` 123 | 124 | If you set up a github repo to store your logs. Then the workflow becomes: 125 | 126 | - from the command line: `log` 127 | - record your notes 128 | - `:Lw` to push this new entry to github 129 | - `:wq` to exit, and you're back. 130 | 131 | This has the advantage of not requiring any directory changes, looing away from your screen, etc. 132 | 133 | # Configuring 134 | 135 | By default, we use environment variables, which can be over-ridden as you see fit, by exporting the variable in `.bashrc` before `source bashlog.sh` 136 | 137 | - `LOG_DIRECTORY`, Default: `~` 138 | - `LOG_EDTIOR`, Default: `vim`; For best effect, the `bashlog.sh` will actually set `LOG_EDITOR` to `vim -S /vim_log`, where `` is, where you put this repo 139 | 140 | You can always adjust these environment variables on the fly as you change working contexts or project workspaces, to keep a consistent pointer to the log directory. 141 | 142 | # Help 143 | 144 | These scripts were yanked from my ever-growing dotfiles repo. If I messed something up, file an issue and let's chat. Also good for suggestions. 145 | 146 | -------------------------------------------------------------------------------- /doc/BulletColor.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jodavaho/bashlog/9a808d84d4b8067c30626b93340a4c5d6dde616e/doc/BulletColor.PNG -------------------------------------------------------------------------------- /init.sh: -------------------------------------------------------------------------------- 1 | mkdir -p ~/.vim/aliases 2 | cp vim_log ~/.vim/aliases/log 3 | cat setup.sh >> ~/.bashrc 4 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | # Bashlog setup 2 | 3 | #Get current directory for fun 4 | 5 | if [ -z "${LOG_EDITOR}" ] 6 | then 7 | export LOG_EDITOR="vim -S ~/.vim/aliases/log" 8 | fi 9 | 10 | if [ ${LOG_ABSOLUTE:-false} = true ] 11 | then 12 | if [ -z "${LOG_DIRECTORY}" ] 13 | then 14 | mkdir -p ~/logs 15 | export LOG_DIRECTORY="~/logs" 16 | fi 17 | echo "Logging to $LOG_DIRECTORY" 18 | else 19 | echo "Relative logging (./)" 20 | export LOG_DIRECTORY="." 21 | fi 22 | 23 | 24 | export date_format="+%Y-%m-%d" 25 | 26 | function lstodo() 27 | { 28 | cmd="grep '\[ \]' * $@ --exclude=*.tmpl" 29 | eval $cmd 30 | } 31 | 32 | function todo() 33 | { 34 | if [ $# -gt 0 ]; 35 | then 36 | echo "Args: $@" 37 | else 38 | eval "$LOG_EDITOR $todofile" 39 | fi 40 | } 41 | 42 | function newish() 43 | { 44 | find $logdir -mtime -10 -type f -not -path '*.git*' 45 | } 46 | 47 | function week() 48 | { 49 | if [ $# -gt 0 ]; then 50 | if [[ $1 == +* ]]; then 51 | local dstring=$(date +%G-week-%V -d "$1 weeks") 52 | elif [[ $1 == -* ]]; then 53 | local dstring=$(date +%G-week-%V -d "$1 weeks") 54 | else 55 | local dstring="$(date +%G-week)-$1" 56 | fi 57 | else 58 | local dstring=$(date +%G-week-%V) 59 | fi 60 | local fname="$dstring.md" 61 | local tmplname="weekly.md.tmpl" 62 | if [ ! -f "$LOG_DIRECTORY/$fname" ] && [ -f "$LOG_DIRECTORY/$tmplname" ]; then 63 | eval "$LOG_EDITOR -c 'cd $LOG_DIRECTORY' -c '0r $LOG_DIRECTORY/$tmplname' $LOG_DIRECTORY/$fname" 64 | else 65 | eval "$LOG_EDITOR $LOG_DIRECTORY/$fname" 66 | fi 67 | } 68 | 69 | function vitodo() 70 | { 71 | if [ -z "$todo" ]; 72 | then 73 | echo "No todo file found ... export '\$todofile'" 74 | return 75 | fi 76 | eval "$LOG_EDITOR $todofile" 77 | } 78 | 79 | function log() 80 | { 81 | local dstring=$(date "$date_format" -d "$*" ) 82 | local fname="$dstring.md" 83 | local tmplname="daily.md.tmpl" 84 | local wnum=$(date "+%V" -d "$*" ) 85 | local ynum=$(date "+%G" -d "$*" ) 86 | echo "D: $dstring W: $wnum Y: $ynum" 87 | if [ ! -f "$LOG_DIRECTORY/$fname" ] && [ -f "$LOG_DIRECTORY/$tmplname" ]; then 88 | #eval "$LOG_EDITOR -c 'cd $LOG_DIRECTORY' -c '0r $LOG_DIRECTORY/$tmplname | :/\$WW/s//\\=strftime(\"%V\")/ | :/\$YY/s//\\=strftime(\"%Y\")/ ' $LOG_DIRECTORY/$fname" 89 | eval "$LOG_EDITOR -c 'cd $LOG_DIRECTORY' -c '0r $LOG_DIRECTORY/$tmplname | :/\$WW/s//$wnum/ | :/\$YY/s//$ynum/ ' $LOG_DIRECTORY/$fname" 90 | else 91 | eval "$LOG_EDITOR $LOG_DIRECTORY/$fname" 92 | fi 93 | } 94 | -------------------------------------------------------------------------------- /vim_log: -------------------------------------------------------------------------------- 1 | set nu 2 | 3 | command Lw w | !git add % && git commit % -m "Checkin %" && git push 4 | 5 | set filetype=markdown 6 | au BufRead,BufNewFile *.md set filetype=markdown 7 | set autochdir 8 | syntax enable 9 | 10 | :highlight TODOTRACK ctermbg=cyan ctermfg=white 11 | :highlight DONETRACK ctermbg=green 12 | :highlight TAGTRACK ctermbg=blue 13 | :highlight REDTRACK ctermbg=red 14 | :highlight PUSHTRACK ctermbg=DarkGray ctermfg=Gray 15 | :highlight TRASHTRACK ctermbg=Black ctermfg=DarkGray 16 | 17 | :let mdone = matchadd("DONETRACK","\\[x\\]") 18 | :let mdone = matchadd("DONETRACK","\\[v\\]") 19 | :let mtodo = matchadd("TODOTRACK", "\\[ \\]") 20 | :let mhigh = matchadd("REDTRACK", "\\[-\\]") 21 | :let mtrash = matchadd("TRASHTRACK", "\\[v\\]") 22 | :let mdelay = matchadd("PUSHTRACK", "\\[>\\]") 23 | 24 | au FileType markdown match DATE "\d\d-\d\d-\d\d" 25 | au FileType markdown match DATE "\d\d-\d\d-\d\d" 26 | au FileType markdown match PROJ "\d\d\d;" 27 | au FileType markdown match PROJ "\w\w\w;" 28 | --------------------------------------------------------------------------------