Skip to content

Commit

Permalink
Add todo tag filtering with #hashtag argument.
Browse files Browse the repository at this point in the history
refs gh-294
  • Loading branch information
xwmx committed Feb 8, 2024
1 parent d65169d commit ce268eb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
19 changes: 12 additions & 7 deletions nb
Original file line number Diff line number Diff line change
Expand Up @@ -25374,17 +25374,22 @@ _todo() {

shift
;;
--tag*)
--tag*|\#*)
[[ -n "${_tag_list_with_commas:-}" ]] && _tag_list_with_commas+=","
_tag_list_with_commas+="$(_option_get_tags "${1}" "${2:-}")"

[[ -n "${_tag_list_with_spaces:-}" ]] && _tag_list_with_spaces+=" "

_tag_list_with_spaces+="$(_option_get_tags "${1}" "${2:-}")"

_tags+=("${2:-}")
if [[ "${1:-}" =~ ^-- ]]
then
_tag_list_with_commas+="$(_option_get_tags "${1}" "${2:-}")"
_tag_list_with_spaces+="$(_option_get_tags "${1}" "${2:-}")"
_tags+=("${2:-}")

shift
shift
else
_tag_list_with_commas+="${1:-}"
_tag_list_with_spaces+="${1:-}"
_tags+=("${1:-}")
fi
;;
--task)
_tasks+=("$(_option_get_value "${1:-}" "${2:-}")")
Expand Down
44 changes: 44 additions & 0 deletions test/todo.bats
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ load test_helper
.*\[.*Example\ Notebook:Example\ Folder/1.*\].*\ ✔️\ \ .*\[\ \].*\ Example\ todo\ description\ one\. ]]
}

# tags ########################################################################

@test "'todos --tags <tag>' exits with 0 and lists todos containing <tag>." {
{
"${_NB}" init
Expand Down Expand Up @@ -165,6 +167,48 @@ load test_helper
.*\[.*2.*\].*\ ✔️\ \ .*\[\ \].*\ Example\ todo\ description\ two\. ]]
}

@test "'todos <tag>' exits with 0 and lists todos containing <tag>." {
{
"${_NB}" init

"${_NB}" add \
--content "# [ ] Example todo description one.${_NEWLINE}${_NEWLINE}#sample-tag" \
--filename "One.todo.md"

sleep 1

"${_NB}" add \
--content "# [ ] Example todo description two.${_NEWLINE}${_NEWLINE}#example-tag" \
--filename "Two.todo.md"

sleep 1

"${_NB}" add \
--content "# [x] Example todo description three.${_NEWLINE}${_NEWLINE}example-tag" \
--filename "Three.todo.md"

sleep 1

"${_NB}" add \
--content "# Example description four.${_NEWLINE}${_NEWLINE}#example-tag" \
--filename "Four.md"
}

run "${_NB}" todos \#example-tag

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 0 ]]

[[ ! "${output}" =~ one ]]
[[ ! "${output}" =~ three ]]
[[ ! "${output}" =~ four ]]

[[ "${lines[0]}" =~ \
.*\[.*2.*\].*\ ✔️\ \ .*\[\ \].*\ Example\ todo\ description\ two\. ]]
}

# todos closed / done #########################################################

@test "'todos closed <notebook>:<folder>/' exits with 0 and lists todos." {
Expand Down

0 comments on commit ce268eb

Please sign in to comment.