Skip to content

Commit

Permalink
Allow category filtering in log command
Browse files Browse the repository at this point in the history
* Resolves #12
  • Loading branch information
iridakos committed Apr 20, 2020
1 parent 24f16a6 commit 589621c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to `stup` will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.1.1] - 2020-04-20

### Added

- Allow logging for a specific category

## [0.1.0] - 2020-04-18

### Initial release
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A CLI tool to easily save, access and organize daily notes.

![Version badge](https://img.shields.io/badge/version-0.1.0-green.svg)
![Version badge](https://img.shields.io/badge/version-0.1.1-green.svg)

The name derives from the [**St**and**up**](https://en.wikipedia.org/wiki/Stand-up_meeting) meetings since its initial purpose was to cover my need for keeping my Standup notes in a convenient way.

Expand Down Expand Up @@ -294,7 +294,7 @@ $ stup log previous-week
The full version of the command:

```bash
$ stup log --from <from-date> --to <to-date>
$ stup log --from <from-date> --to <to-date> -c <category-name>

# or using an alias

Expand All @@ -307,6 +307,8 @@ where:
- this is optional and if omitted the notes to be displayed won't have be **added after a specific date**
- `<to-date>`: is also a date alias (`today`, `yesterday`, `tomorrow`) or a specific date using the format `YYYY-MM-DD`, for example: 2020-04-18
- this is also optional and if omitted the notes to be displayed won't have be **added before a specific date**
* `-c` or `--category`: is the category option (optional). **If omitted, you will view the notes of all categories**
* `<category-name>`: the name of the category whose notes you want to see

In the second version of the command, you can use the temporal aliases that will be translated to proper from/to dates.

Expand Down
29 changes: 20 additions & 9 deletions stup
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ execute_log()
echo -e "$(print_info "Displaying all notes")"
fi

local target_categories

if [ -n "$CATEGORY" ]; then
target_categories=("$CATEGORY")
else
target_categories=( "${CATEGORIES[@]}" )
fi

local output=""

for current_date in ${dates[@]}; do
Expand All @@ -397,28 +405,31 @@ execute_log()
AT="$current_date"
extract_date_components

output+="$(printf "%-10s %s" "Date:" "$(emphasize "$(display_date "$AT")")")"
output+="\n"

local category_count=0
local category_output=""

for category in "${CATEGORIES[@]}"; do
for category in "${target_categories[@]}"; do
local target_file="$(resolve_target_file "$category")"

if [ -f "$target_file" ]; then
category_count=$((category_count + 1))

if [ "$category_count" -gt "1" ]; then
output+="\n"
category_output+="\n"
fi

output+="$(printf "%-10s %s" "Category:" "$(print_warning "$category")")"
output+="\n\n"
output+="$(sed -e 's/^-/•/' -e 's/^/ /' "$target_file")\n"
category_output+="$(printf "%-10s %s" "Category:" "$(print_warning "$category")")"
category_output+="\n\n"
category_output+="$(sed -e 's/^-/•/' -e 's/^/ /' "$target_file")\n"
fi
done

output+="\n"
if [ -n "$category_output" ]; then
output+="$(printf "%-10s %s" "Date:" "$(emphasize "$(display_date "$AT")")")"
output+="\n"
output+="$category_output"
output+="\n"
fi
done

if [ -z "$output" ]; then
Expand Down

0 comments on commit 589621c

Please sign in to comment.