From 2554f22ab952eb03ca769de66a90a0ebd9066b51 Mon Sep 17 00:00:00 2001 From: Abhishek Keshri Date: Thu, 20 Feb 2025 23:14:09 +0530 Subject: [PATCH 1/6] feat: add completions --- completions/tdo_completion.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 completions/tdo_completion.sh diff --git a/completions/tdo_completion.sh b/completions/tdo_completion.sh new file mode 100644 index 0000000..1b3bb67 --- /dev/null +++ b/completions/tdo_completion.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +_tdo_completions() { + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD - 1]}" + opts=$(gfind "$NOTES_DIR" -type f -not -path '*/\.*' -printf '%P\n') + + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 +} + +complete -F _tdo_completions tdo From 623e0479fb5ee21c13fdfada2decc0c9c3023412 Mon Sep 17 00:00:00 2001 From: Abhishek Keshri Date: Fri, 21 Feb 2025 01:11:46 +0530 Subject: [PATCH 2/6] feat: platform independent, no find/gfind --- completions/tdo_completion.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/completions/tdo_completion.sh b/completions/tdo_completion.sh index 1b3bb67..4fa43ba 100644 --- a/completions/tdo_completion.sh +++ b/completions/tdo_completion.sh @@ -1,14 +1,13 @@ #!/usr/bin/env bash _tdo_completions() { - local cur prev opts - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD - 1]}" - opts=$(gfind "$NOTES_DIR" -type f -not -path '*/\.*' -printf '%P\n') + local cur opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + opts=$(find "$NOTES_DIR" -mindepth 1 -not -path '*/\.*' | sed "s|^$NOTES_DIR/||") - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) - return 0 + COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) + return 0 } complete -F _tdo_completions tdo From bca400a5e1b90209b2f0dc4d1dbde8fac97d30e3 Mon Sep 17 00:00:00 2001 From: Abhishek Keshri Date: Sat, 22 Feb 2025 06:30:08 +0530 Subject: [PATCH 3/6] feat: handle existing files during note creation --- tdo.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tdo.sh b/tdo.sh index 4697f03..2d3e563 100755 --- a/tdo.sh +++ b/tdo.sh @@ -199,6 +199,12 @@ new_entry() { find_or_create_note() { root="$NOTES_DIR" + + if [ -f "$root/$1" ]; then + write_file "$root/$1" "$root" + return + fi + note_file="$root/notes/$1.md" template="$root/templates/note.md" notes=$(find "$root" -type f -not -path '*/\.*' -iname "*$1*") From 80ea8f187ac5a92857f5a3a7d95d49fea6a9ea5d Mon Sep 17 00:00:00 2001 From: Abhishek Keshri Date: Sat, 22 Feb 2025 07:01:45 +0530 Subject: [PATCH 4/6] feat: add sort to comp list --- completions/tdo_completion.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/completions/tdo_completion.sh b/completions/tdo_completion.sh index 4fa43ba..faa3816 100644 --- a/completions/tdo_completion.sh +++ b/completions/tdo_completion.sh @@ -4,8 +4,9 @@ _tdo_completions() { local cur opts COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" - opts=$(find "$NOTES_DIR" -mindepth 1 -not -path '*/\.*' | sed "s|^$NOTES_DIR/||") + opts=$(find "$NOTES_DIR" -mindepth 1 -not -path '*/\.*' | sed "s|^$NOTES_DIR/||" | sort) + local IFS=$'\n' COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) return 0 } From 956d53527430d6de57c7b48467755ccbccc74808 Mon Sep 17 00:00:00 2001 From: Abhishek Keshri Date: Sat, 22 Feb 2025 07:05:21 +0530 Subject: [PATCH 5/6] feat: only show files in completion --- completions/tdo_completion.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/tdo_completion.sh b/completions/tdo_completion.sh index faa3816..3230f76 100644 --- a/completions/tdo_completion.sh +++ b/completions/tdo_completion.sh @@ -4,7 +4,7 @@ _tdo_completions() { local cur opts COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" - opts=$(find "$NOTES_DIR" -mindepth 1 -not -path '*/\.*' | sed "s|^$NOTES_DIR/||" | sort) + opts=$(find "$NOTES_DIR" -type f -not -path '*/\.*' | sed "s|^$NOTES_DIR/||" | sort) local IFS=$'\n' COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) From d197439782f246bbe1a6f66839124a7ed921a387 Mon Sep 17 00:00:00 2001 From: Abhishek Keshri Date: Sat, 22 Feb 2025 08:00:45 +0530 Subject: [PATCH 6/6] docs: mention shell completion --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index eb2f770..08a61d7 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,16 @@ cp -irv templates $NOTES_DIR source ~/.zshrc ``` +#### 🔤 Shell Completion + +If you want to enable tab completion for `tdo`, add this to your shell's RC file (~/.bashrc, ~/.zshrc): + +```bash +source /path/to/tdo/completions/tdo_completion.sh +``` + +This will allow you to use tab completion to quickly access your notes when you type `tdo `. + #### 💾 Git Integration If you want to sync your notes across devices, you can set up a git repo on the $NOTES_DIR and add GitHub/GitLab as remote.