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 env variables and tdorc config options #10

Merged
merged 9 commits into from
Apr 7, 2024
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
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tdo is a opinionated, command line based note-taking system. [Demo video](https:

## ⚡ Setup

### ⚙️ Requirements
### 📋 Requirements

- ripgrep, fzf
- bat (optional, for syntax highlighting in search)
Expand Down Expand Up @@ -146,6 +146,30 @@ If you use Neovim, I highly recommend using [tdo.nvim](https://github.com/2kabhi
   └── todo.md
```

### ⚙️ Configuration

You can configure `tdo` by either defining environment variables or via a `$HOME/.config/tdorc` file.

- `ADD_ENTRY_TIMESTAMP` `[boolean]`: Whether to add a time stamp when using `tdo entry` or `tdo e`.
- `ADD_NEW_NOTE_TIMESTAMP` `[boolean]`: Whether to add a time stamp when creating new notes with `tdo <note_title>`.
- `FILE_NAME_AS_TITLE` `[boolean]`: Whether to add the file name as title when creating new notes with `tdo <note_title>`. If `true`, then it adds `<note_title>` as a markdown title in the first line of the new note.
- `ENTRY_TIMESTAMP_FORMAT` `[string]`: can be any bash string such as a date format expression. It is ignored if `ADD_ENTRY_TIMESTAMP` is set to `false`.
- `NOTE_TIMESTAMP_FORMAT`(`[string]`: can be any bash string such as a date format expression. It is ignored if `ADD_NEW_NOTE_TIMESTAMP` is set to `false`.

#### Default Configs

```bash
ADD_ENTRY_TIMESTAMP=true
ADD_NEW_NOTE_TIMESTAMP=false
FILE_NAME_AS_TITLE=false
# Reads ## Mon, 12:00 PM
ENTRY_TIMESTAMP_FORMAT="## %a, %I:%M %p"
# Reads ## Fri. Apr 06, 2024 - 06:48 PM
NOTE_TIMESTAMP_FORMAT="## %a. %b %d, %Y - %I:%M %p"
```

> configs defined in `tdorc` will override corresponding environment variables

## 🏗️ What's Next

You tell me!
Expand Down
23 changes: 19 additions & 4 deletions tdo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ For more information, visit https://github.com/2kabhishek/tdo
EOF
}

config_setup() {
source $HOME/.config/tdorc

add_entry_timestamp="${ADD_ENTRY_TIMESTAMP:-true}"
add_new_note_timestamp="${ADD_NEW_NOTE_TIMESTAMP:-false}"
filename_as_title="${FILE_NAME_AS_TITLE:-false}"
entry_timestamp_format="${ENTRY_TIMESTAMP_FORMAT:-"## %a, %I:%M %p"}"
note_timestamp_format="${NOTE_TIMESTAMP_FORMAT:-"## %a. %b %d, %Y - %I:%M %p"}"
}

check_command() {
if ! command -v "$1" &>/dev/null; then
echo "Error: The $1 command is not available. Make sure it is installed."
Expand Down Expand Up @@ -96,9 +106,9 @@ create_file() {

add_timestamp() {
file_path="$1"
time_format="${2:-%a, %I:%M %p}"
time_format="${2:-## %a, %I:%M %p}"
timestamp=$(date +"$time_format")
echo -e "\n## $timestamp\n" >>"$file_path"
echo -e "\n$timestamp\n" >>"$file_path"
}

write_file() {
Expand Down Expand Up @@ -151,7 +161,11 @@ new_note() {
root="$NOTES_DIR"
note_file="$root/notes/$1.md"
template="$root/templates/note.md"
create_file "$note_file" "$template"
if [ ! -f "$note_file" ]; then
create_file "$note_file" "$template"
$filename_as_title && echo -e "# $1" >>"$note_file"
$add_new_note_timestamp && add_timestamp "$note_file" "$note_timestamp_format"
fi
write_file "$note_file" "$root"
}

Expand All @@ -173,14 +187,15 @@ new_entry() {
entry_file="$root/entries/$(generate_file_path "$1")"
template="$root/templates/entry.md"
create_file "$entry_file" "$template"
add_timestamp "$entry_file"
$add_entry_timestamp && add_timestamp "$entry_file" "$entry_timestamp_format"
write_file "$entry_file" "$root"
}

main() {
check_command "rg"
check_command "fzf"
check_env "NOTES_DIR"
config_setup

case "$1" in
-c | --commit | c | commit) commit_changes "$(dirname "$2")" ;;
Expand Down