Skip to content

Commit

Permalink
Choose directory for theme installation for RStudio 1.2 or 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie committed Nov 1, 2019
1 parent c787f3c commit d1a82c9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rsthemes
Title: Full Themes for RStudio v1.2+
Version: 0.0.2
Version: 0.0.3
Authors@R:
person(given = "Garrick",
family = "Aden-Buie",
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# rsthemes 0.0.3

* Choose theme installation directory based on RStudio version. For 1.3.555+ the
themes are now installed into `~/.config/rstudio/themes`. An additional
`destdir` argument was added to `install_rsthemes()` for future flexibility.
Related to this RStudio desktop issue:
https://github.com/rstudio/rstudio/issues/5674#issuecomment-548484300.
(thanks @pat-s)

# rsthemes 0.0.2

* Added automatic light/dark mode switching with `use_theme_auto()` and
Expand Down
19 changes: 14 additions & 5 deletions R/rsthemes.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#' provide an easy-to-extend framework for customizing the look of RStudio. See
#' [new_rstheme()] for more information about creating your own theme. I've done
#' my best to avoid hacky CSS rules wherever possible, and the themes are tested
#' against the current production release of RStudio (verision 1.2.1335 as of
#' June 11, 2019). Please report any issues you encounter here:
#' against the current production release of RStudio (version 1.2.1335 through
#' 1.3+ as of November 1, 2019). Please report any issues you encounter here:
#' [github.com/gadenbuie/rsthemes/issues](https://github.com/gadenbuie/rsthemes/issues).
#'
#' @name rsthemes
Expand All @@ -18,17 +18,26 @@ NULL
#' @param style Limit to a subgroup of themes, chosen from the options returned
#' by [rsthemes_styles()].
#' @param include_base16 Should the `base16` themes be included?
#' @param destdir The desination directory for the `.rstheme` files. By default
#' will attempt to choose the correct directory for the current RStudio
#' version 1.2 or 1.3+.
#' @export
install_rsthemes <- function(style = "all", include_base16 = FALSE) {
install_rsthemes <- function(style = "all", include_base16 = FALSE, destdir = NULL) {
theme_files <- list_pkg_rsthemes(style, include_base16)
theme_files <- unname(theme_files)

theme_rstudio_files <- paste0("rsthemes_", fs::path_file(theme_files))

fs::dir_create(rstudio_theme_home())
if (is.null(destdir)) {
destdir <- rstudio_theme_home()
message("Installing themes to ", destdir)
}
destdir <- fs::path_abs(destdir)
fs::dir_create(destdir)

fs::file_copy(
theme_files,
fs::path(rstudio_theme_home(), theme_rstudio_files),
fs::path(destdir, theme_rstudio_files),
overwrite = TRUE
)
message("Installed ", length(theme_files), " themes, ",
Expand Down
6 changes: 5 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ package_template <- function(...) {
}

rstudio_theme_home <- function(...) {
fs::path_home_r(".R", "rstudio", "themes", ...)
if (rstudioapi::versionInfo()$version >= "1.3.555") {
fs::path_home_r(".config", "rstudio", "themes", ...)
} else {
fs::path_home_r(".R", "rstudio", "themes", ...)
}
}

cp_to_rstudio <- function(file, overwrite = TRUE) {
Expand Down
11 changes: 8 additions & 3 deletions man/rsthemes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d1a82c9

Please sign in to comment.