Last active
December 14, 2023 22:06
-
-
Save tjmahr/f63c21ad044311f7433999e97cbbfcd8 to your computer and use it in GitHub Desktop.
bib_glance()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bib_glance <- function(sort = TRUE) { | |
path <- "./notebook/refs.bib" | |
refs <- bibtex::read.bib(path) | |
if (sort) { | |
refs <- refs[sort(names(refs))] | |
} | |
titles <- purrr::map_chr(refs, purrr::pluck, "title") |> | |
stringr::str_replace_all("\\{|\\}", "") |> | |
stringr::str_replace_all("\\s\\s+", " ") | |
preview_width <- unlist(options("width")) - max(nchar(names(refs))) - 3 | |
short_titles <- ifelse( | |
nchar(titles) > (preview_width - 3), | |
paste0(substr(titles, 1, (preview_width - 3)), "..."), | |
titles | |
) | |
tags <- paste0("[@", names(refs), "]") | |
padded <- stringr::str_pad(tags, max(nchar(tags)), "left") | |
cli::cli_text("bibliography {.file {path}}:") | |
print(glue::glue("{padded} {short_titles}")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment