diff options
| -rwxr-xr-x | bin/todo | 107 |
1 files changed, 56 insertions, 51 deletions
diff --git a/bin/todo b/bin/todo index 1fe3c62..d22f47a 100755 --- a/bin/todo +++ b/bin/todo @@ -1,18 +1,20 @@ #!/bin/bash +set -e +[ -n "$DEBUG" ] && set -x -_todo_files=(".todo.md" ".org.md", "TODO") +_todo_files=(".todo.md" ".org.md" "TODO" "todo.org" "todo.md") _todo_file="" has_todo_file() { - cwd=`pwd` - for f in ${_todo_files[@]}; do - [[ -f "$cwd/$f" ]] && _todo_file="$cwd/$f" && return 0 - done - return 1 + cwd=$(pwd) + for f in "${_todo_files[@]}"; do + test -f "$cwd/$f" && _todo_file="$cwd/$f" && return 0 + done + return 1 } print_org() { - awk ' + awk ' function filename() { n = split(FILENAME, a, "/") return a[n] @@ -74,55 +76,58 @@ END { } print_shell_hook() { - case $1 in - zsh) - echo "_orgdown_hook() {$0;} + case $1 in + zsh) + echo "_orgdown_hook() {$0;} typeset -ag precmd_functions; if [[ -z \${precmd_functions[(r)_orgdown_hook]} ]]; then precmd_functions+=_orgdown_hook; fi" - ;; - cd) - echo "cd() { builtin cd \"\$@\" && $0; }" - ;; - -h|--help|*) - echo "usage: todo hook <integration>" - echo "" - echo "supported integrations:" - echo " - zsh: run todo as a precmd hook" - echo " (this can get quite annoying when you're in a direcory that has a todo file)" - echo " - cd: run todo as a post-cd hook" - echo "" - exit 1 - ;; - esac + ;; + cd) + echo "cd() { builtin cd \"\$@\" && $0; }" + ;; + -h | --help | *) + echo "usage: todo hook <integration>" + echo "" + echo "supported integrations:" + echo " - zsh: run todo as a precmd hook" + echo " (this can get quite annoying when you're in a direcory that has a todo file)" + echo " - cd: run todo as a post-cd hook" + echo "" + exit 1 + ;; + esac } case "$1" in - hook) - shift - print_shell_hook "$1" - ;; - -h|--help) - echo "usage: todo [-r] [hook <integration>]" - echo "A quite stupid todo/agenda script that reminds you of things you need to do" - echo "" - echo " -r, --recursive walk the file tree, searching for todos" - echo " <integration> shell integration, you should eval this" - echo "" - exit 0 - ;; - -r|--recursive|-R) - while read FILE; do - hr "todo [$FILE]" - print_org $FILE; - done < <(rg --files ${_todo_files[@]/#/-g }) - ;; - *) - [ -f "$1" ] && { print_org $1; exit 0; } - has_todo_file && { - hr "todo" - print_org $_todo_file - } - ;; +hook) + shift + print_shell_hook "$1" + ;; +-h | --help) + echo "usage: todo [-r] [hook <integration>]" + echo "A quite stupid todo/agenda script that reminds you of things you need to do" + echo "" + echo " -r, --recursive walk the file tree, searching for todos" + echo " <integration> shell integration, you should eval this" + echo "" + exit 0 + ;; +-r | --recursive | -R) + while read FILE; do + hr "todo [$FILE]" + print_org $FILE + done < <(rg --files ${_todo_files[@]/#/-g }) + ;; +*) + [ -f "$1" ] && { + print_org $1 + exit 0 + } + has_todo_file && { + hr "todo" + print_org $_todo_file + } + ;; esac |