Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic tab completion support #12

Merged
merged 6 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tab>`.

#### 💾 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.
Expand Down
14 changes: 14 additions & 0 deletions completions/tdo_completion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

_tdo_completions() {
local cur opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
opts=$(find "$NOTES_DIR" -type f -not -path '*/\.*' | sed "s|^$NOTES_DIR/||" | sort)

local IFS=$'\n'
COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
return 0
}

complete -F _tdo_completions tdo
6 changes: 6 additions & 0 deletions tdo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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*")
Expand Down