diff --git a/nb b/nb index 347fbeac3..72323fb53 100755 --- a/nb +++ b/nb @@ -13500,6 +13500,11 @@ _bookmark() { elif [[ -z "${_subcommand:-}" ]] || [[ "${_subcommand}" =~ (^list$|^search$) ]] then + if [[ "${1:-}" =~ (:|^/) ]] && [[ -z "${_selector:-}" ]] + then + _selector="${1:-}" + fi + _arguments+=("${1}") fi ;; @@ -13726,6 +13731,7 @@ _bookmark() { fi # `bookmark ` + if ((${#_secondary_urls[@]})) then local __url= @@ -13747,6 +13753,11 @@ _bookmark() { | sed 's/https:\/\/twitter.com/https:\/\/mobile.twitter.com/g' )" + if [[ "${_selector}" =~ (:|^/) ]] + then + _notebooks select "${_selector}" + fi + local _relative_folder_path= local _relative_path= diff --git a/test/bookmark.bats b/test/bookmark.bats index 70695d791..12087c42e 100644 --- a/test/bookmark.bats +++ b/test/bookmark.bats @@ -739,6 +739,74 @@ HEREDOC [[ "${lines[0]}" =~ Added:\ .*[.*Example\ Notebook:1.*].*\ .*example.bookmark.md ]] } + +@test "'nb : ' with no options creates new bookmark." { + { + "${_NB}" init + + "${_NB}" notebooks add "Example Notebook" + "${_NB}" notebooks add "demo" + "${_NB}" notebooks add "sample" + } + + run "${_NB}" \ + "Example Notebook:" \ + "${_BOOKMARK_URL}" + + printf "\${status}: '%s'\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" + + # Returns status 0: + + [[ "${status}" -eq 0 ]] + + # Creates new bookmark file with content: + + _files=($(ls "${NB_DIR}/Example Notebook/")) + + [[ "${#_files[@]}" -eq 1 ]] + + [[ -f "${NB_DIR}/Example Notebook/${_files[0]}" ]] + + diff \ + <(cat "${NB_DIR}/Example Notebook/${_files[0]}") \ + <(cat < + +## Description + +Example description. + +## Content + +$(cat "${NB_TEST_BASE_PATH}/fixtures/example.com.md") +HEREDOC +) + + # Creates git commit: + + cd "${NB_DIR}/Example Notebook" || return 1 + while [[ -n "$(git status --porcelain)" ]] + do + sleep 1 + done + git log | grep -q '\[nb\] Add' + + # Adds to index: + + [[ -e "${NB_DIR}/Example Notebook/.index" ]] + + diff \ + <(ls "${NB_DIR}/Example Notebook") \ + <(cat "${NB_DIR}/Example Notebook/.index") + + # Prints output: + + [[ "${lines[0]}" =~ Added:\ .*[.*Example\ Notebook:1.*].*\ .*.bookmark.md ]] +} + # `add bookmark` ############################################################## @test "'add bookmark' with --tags, --filename, and --related options creates new bookmark." { @@ -2021,6 +2089,232 @@ $(cat "${NB_TEST_BASE_PATH}/fixtures/example.com.md")" git log | grep -q '\[nb\] Add' } +# `bookmark :` ########################################################### + +@test "'nb bookmark : ' with --tags, --filename, and --related options creates new bookmark." { + { + "${_NB}" init + + "${_NB}" notebooks add "Example Notebook" + "${_NB}" notebooks add "demo" + "${_NB}" notebooks add "sample" + } + + run "${_NB}" \ + bookmark \ + "Example Notebook:" \ + "${_BOOKMARK_URL}" \ + --tags tag1,tag2 \ + --filename "example" \ + --related http://example.org \ + --related sample:123 \ + --related "[[demo:456]]" \ + --related "Example Title" + + printf "\${status}: '%s'\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" + + # Returns status 0: + + [[ "${status}" -eq 0 ]] + + # Creates new bookmark file with content: + + [[ -f "${NB_DIR}/Example Notebook/example.bookmark.md" ]] + + diff \ + <(cat "${NB_DIR}/Example Notebook/example.bookmark.md") \ + <(cat < + +## Description + +Example description. + +## Related + +- +- [[sample:123]] +- [[demo:456]] +- [[Example Title]] + +## Tags + +#tag1 #tag2 + +## Content + +$(cat "${NB_TEST_BASE_PATH}/fixtures/example.com.md") +HEREDOC +) + + # Creates git commit: + + cd "${NB_DIR}/Example Notebook" || return 1 + while [[ -n "$(git status --porcelain)" ]] + do + sleep 1 + done + git log | grep -q '\[nb\] Add' + + # Adds to index: + + [[ -e "${NB_DIR}/Example Notebook/.index" ]] + + diff \ + <(ls "${NB_DIR}/Example Notebook") \ + <(cat "${NB_DIR}/Example Notebook/.index") + + # Prints output: + + [[ "${lines[0]}" =~ Added:\ .*[.*Example\ Notebook:1.*].*\ .*example.bookmark.md ]] +} + + +@test "'nb bookmark : ' with no options creates new bookmark." { + { + "${_NB}" init + + "${_NB}" notebooks add "Example Notebook" + "${_NB}" notebooks add "demo" + "${_NB}" notebooks add "sample" + } + + run "${_NB}" \ + bookmark \ + "Example Notebook:" \ + "${_BOOKMARK_URL}" + + printf "\${status}: '%s'\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" + + # Returns status 0: + + [[ "${status}" -eq 0 ]] + + # Creates new bookmark file with content: + + _files=($(ls "${NB_DIR}/Example Notebook/")) + + [[ "${#_files[@]}" -eq 1 ]] + + [[ -f "${NB_DIR}/Example Notebook/${_files[0]}" ]] + + diff \ + <(cat "${NB_DIR}/Example Notebook/${_files[0]}") \ + <(cat < + +## Description + +Example description. + +## Content + +$(cat "${NB_TEST_BASE_PATH}/fixtures/example.com.md") +HEREDOC +) + + # Creates git commit: + + cd "${NB_DIR}/Example Notebook" || return 1 + while [[ -n "$(git status --porcelain)" ]] + do + sleep 1 + done + git log | grep -q '\[nb\] Add' + + # Adds to index: + + [[ -e "${NB_DIR}/Example Notebook/.index" ]] + + diff \ + <(ls "${NB_DIR}/Example Notebook") \ + <(cat "${NB_DIR}/Example Notebook/.index") + + # Prints output: + + [[ "${lines[0]}" =~ Added:\ .*[.*Example\ Notebook:1.*].*\ .*.bookmark.md ]] +} + +@test "'nb bookmark :/ ' with no options creates new bookmark." { + { + "${_NB}" init + + "${_NB}" notebooks add "Example Notebook" + "${_NB}" notebooks add "demo" + "${_NB}" notebooks add "sample" + } + + run "${_NB}" \ + bookmark \ + "Example Notebook:Example Folder/" \ + "${_BOOKMARK_URL}" <<< "y${_NEWLINE}" + + printf "\${status}: '%s'\\n" "${status}" + printf "\${output}: '%s'\\n" "${output}" + + # Returns status 0: + + [[ "${status}" -eq 0 ]] + + # Creates new bookmark file with content: + + _files=($(ls "${NB_DIR}/Example Notebook/Example Folder/")) + + [[ "${#_files[@]}" -eq 1 ]] + + [[ -f "${NB_DIR}/Example Notebook/Example Folder/${_files[0]}" ]] + + diff \ + <(cat "${NB_DIR}/Example Notebook/Example Folder/${_files[0]}") \ + <(cat < + +## Description + +Example description. + +## Content + +$(cat "${NB_TEST_BASE_PATH}/fixtures/example.com.md") +HEREDOC +) + + # Creates git commit: + + cd "${NB_DIR}/Example Notebook" || return 1 + while [[ -n "$(git status --porcelain)" ]] + do + sleep 1 + done + git log | grep -q '\[nb\] Add' + + # Adds to index: + + [[ -e "${NB_DIR}/Example Notebook/.index" ]] + [[ -e "${NB_DIR}/Example Notebook/Example Folder/.index" ]] + + diff \ + <(ls "${NB_DIR}/Example Notebook") \ + <(cat "${NB_DIR}/Example Notebook/.index") + + diff \ + <(ls "${NB_DIR}/Example Notebook/Example Folder") \ + <(cat "${NB_DIR}/Example Notebook/Example Folder/.index") + + # Prints output: + + [[ "${lines[0]}" =~ Creating\ new\ folder:\ .*Example\ Notebook:Example\ Folder/ ]] + [[ "${lines[1]}" =~ Added:\ .*[.*Example\ Notebook:Example\ Folder/1.*].*\ .*.bookmark.md ]] +} + # `bookmark delete` ########################################################### @test "'bookmark delete' deletes properly without errors." {