diff --git a/README.md b/README.md index 9784936..eb2f770 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 `. +- `FILE_NAME_AS_TITLE` `[boolean]`: Whether to add the file name as title when creating new notes with `tdo `. If `true`, then it adds `` 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! diff --git a/tdo.sh b/tdo.sh index fc73ca3..080e530 100755 --- a/tdo.sh +++ b/tdo.sh @@ -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." @@ -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() { @@ -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" } @@ -173,7 +187,7 @@ 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" } @@ -181,6 +195,7 @@ main() { check_command "rg" check_command "fzf" check_env "NOTES_DIR" + config_setup case "$1" in -c | --commit | c | commit) commit_changes "$(dirname "$2")" ;;