Skip to content

Commit

Permalink
Only search non-bookmark items with search --type note.
Browse files Browse the repository at this point in the history
refs gh-166
  • Loading branch information
xwmx committed Aug 29, 2024
1 parent 72e97b3 commit 254ea5f
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nb
Original file line number Diff line number Diff line change
Expand Up @@ -17633,8 +17633,9 @@ _search() {
[[ "${_type}" =~ (^todo$|^todos$|^task$|^tasks$) ]] &&
_file_is_todo "${_path}"
} || {
[[ "${_type}" =~ (^note$|^notes$|^text$) ]] &&
_file_is_text "${_path}"
[[ "${_type}" =~ (^note$|^notes$) ]] &&
_file_is_text "${_path}" &&
[[ ! "${_path:-}" =~ (.bookmark.md$|-bookmark.md$) ]]
} || {
[[ "${_type}" =~ (^folder$|^folders$) ]] &&
[[ "$(dirname "${_path}")" != "${__target_path}" ]]
Expand All @@ -17653,6 +17654,9 @@ _search() {
} || {
[[ "${_type}" =~ (^image$|^images$|^picture$|^pictures$) ]] &&
_file_is_image "${_path}"
} || {
[[ "${_type}" =~ ^text$ ]] &&
_file_is_text "${_path}"
} || {
[[ "${_type}" =~ (^video$|^videos$) ]] &&
_file_is_video "${_path}"
Expand Down
76 changes: 76 additions & 0 deletions test/search.bats
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,82 @@ _search_all_setup() {

# --type <type> ###############################################################

@test "'search <query> --type note' only searches items of type note." {
{
"${_NB}" init

"${_NB}" add \
--content "# Example File One Content" \
--filename "File One.md"

"${_NB}" add \
--content "<http://example.test/>" \
--filename "File Two.bookmark.md"

"${_NB}" add \
--content "# Example File Three Content" \
--filename "File Three.md"

"${_NB}" add \
--content "<http://example.test/>" \
--filename "File Four.bookmark.md"
}

run "${_NB}" search "example" --type note

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
# printf "\${lines[0]}: '%s'\\n" "${lines[0]}"
printf "\${#lines[@]}: '%s'\\n" "${#lines[@]}"

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

[[ "${#lines[@]}" -eq 6 ]]

[[ "${lines[0]}" =~ Example\ File\ One ]]
[[ "${lines[1]}" =~ -*- ]]
[[ "${lines[2]}" =~ Example.*\ File\ One ]]

[[ ! "${output}" =~ example.*\.test ]]
}

@test "'search <query> --type text' only searches items of type text." {
{
"${_NB}" init

"${_NB}" add \
--content "# Example File One Content" \
--filename "File One.md"

"${_NB}" add \
--content "<http://example.test/>" \
--filename "File Two.bookmark.md"

"${_NB}" add \
--content "# Example File Three Content" \
--filename "File Three.md"

"${_NB}" add \
--content "<http://example.test/>" \
--filename "File Four.bookmark.md"
}

run "${_NB}" search "example" --type text

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
# printf "\${lines[0]}: '%s'\\n" "${lines[0]}"
printf "\${#lines[@]}: '%s'\\n" "${#lines[@]}"

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

[[ "${#lines[@]}" -eq 12 ]]

[[ "${lines[0]}" =~ File\ Four.bookmark.md ]]
[[ "${lines[1]}" =~ -*- ]]
[[ "${lines[2]}" =~ example.*\.test ]]
}

@test "'search <query> --type <type>' only searches items of type <type>." {
{
_setup_search
Expand Down

0 comments on commit 254ea5f

Please sign in to comment.