Browse Source

plutil

master
boB Rudis 4 years ago
parent
commit
d6d4ac0128
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 1
      DESCRIPTION
  2. 1
      NAMESPACE
  3. 13
      R/addin.R
  4. 1
      R/bitbar-package.R
  5. 12
      R/read-bitbar-prefs.R
  6. 26
      R/use-bitbar.R
  7. 15
      inst/templates/bitbar.R
  8. 8
      man/new_bitbar_script.Rd

1
DESCRIPTION

@ -21,7 +21,6 @@ Imports:
usethis,
magrittr,
clipr,
XML,
httr,
sys,
miniUI,

1
NAMESPACE

@ -11,6 +11,5 @@ export(r_logo_small)
import(httr)
import(miniUI)
import(shiny)
importFrom(XML,readKeyValueDB)
importFrom(magrittr,"%>%")
importFrom(usethis,use_template)

13
R/addin.R

@ -8,6 +8,9 @@ create_new_bitbar_script <- function() {
value = file.path(bitbar_plugins_dir(), sprintf("%s-new-plugin.R", ulid::generate())),
),
shiny::textInput(
inputId = "refresh", label = "Run every (leave blank for no auto-refresh):", value = "", width="100%",
),
shiny::textInput(
inputId = "title", label = "Title:", value = "Script Title", width="100%",
),
shiny::textInput(
@ -47,7 +50,8 @@ create_new_bitbar_script <- function() {
description = input$description,
dependencies = input$dependencies,
image_url = input$image_url,
about_url = input$about_url
about_url = input$about_url,
refresh = input$refresh
)
stopApp(
@ -60,7 +64,8 @@ create_new_bitbar_script <- function() {
description = input$description,
dependencies = input$dependencies,
image_url = input$image_url,
about_url = input$about_url
about_url = input$about_url,
refresh = input$refresh
)
)
@ -68,9 +73,9 @@ create_new_bitbar_script <- function() {
}
viewer <- dialogViewer("New BitBar", width = 400, height = 800)
viewer <- dialogViewer("New BitBar", width = 400, height = 600)
runGadget(ui, server, viewer = viewer)
invisible(runGadget(ui, server, viewer = viewer))
}

1
R/bitbar-package.R

@ -21,7 +21,6 @@
#' @md
#' @name bitbar
#' @importFrom usethis use_template
#' @importFrom XML readKeyValueDB
#' @import httr shiny miniUI
#' @keywords internal
#' @author Bob Rudis (bob@@rud.is)

12
R/read-bitbar-prefs.R

@ -14,17 +14,14 @@ read_bitbar_prefs <- function() {
)
}
tf <- tempfile(fileext = ".xml")
on.exit(unlink(tf))
sys::exec_internal(
cmd = "plistutil",
args = c("--infile", bbprefs, "--outfile", tf)
cmd = "/usr/bin/plutil",
args = c("-extract", "pluginsDirectory", "swift", "-o", "-", bbprefs)
) -> res
if (res$status == 0) {
res <- XML::readKeyValueDB(tf)
res <- gsub('"', "", sub('^[^"]+', "", rawToChar(res$stdout)))
res
} else {
@ -37,6 +34,5 @@ read_bitbar_prefs <- function() {
#'
#' @export
bitbar_plugins_dir <- function() {
prefs <- read_bitbar_prefs()
prefs[["pluginsDirectory"]]
read_bitbar_prefs()
}

26
R/use-bitbar.R

@ -3,6 +3,10 @@
#' @param save_as full path (including scriptname.R) to where you want the file saved
#' @param title,version,author,github_user,description,dependencies,image_url,about_url
#' BitBar metadata passed on to the generator.
#' @param refesh if non-blank this will cause the filename to include a refresh hint
#' in the `save_as` filename before the ending `.R` so BitBar will run the script
#' every `refresh` period. See [Configuring the refresh time](https://github.com/matryer/bitbar#configure-the-refresh-time)
#' for more information.
#' @export
#' @examples
#' if (interactive()) {
@ -20,7 +24,8 @@ new_bitbar_script <- function(save_as,
description = "BitBar Plugin Using R",
dependencies = "R",
image_url = "",
about_url = "") {
about_url = "",
refresh = "") {
usethis:::render_template(
template = "bitbar.R",
@ -38,14 +43,25 @@ new_bitbar_script <- function(save_as,
)
) -> rendered_template
writeLines(rendered_template, con = path.expand(save_as))
save_as <- path.expand(save_as)
Sys.chmod(path.expand(save_as), "0755")
if (refresh[1] != "") {
file.path(sprintf(
"%s.%s.%s",
tools::file_path_sans_ext(save_as),
refresh,
tools::file_ext(save_as)
)) -> save_as
}
writeLines(rendered_template, con = save_as)
Sys.chmod(save_as, "0755")
if (rstudioapi::isAvailable() && rstudioapi::hasFun("navigateToFile")) {
rstudioapi::navigateToFile(path.expand(save_as))
rstudioapi::navigateToFile(save_as)
} else {
utils::file.edit(path.expand(save_as))
utils::file.edit(save_as)
}
}

15
inst/templates/bitbar.R

@ -8,6 +8,21 @@
# <bitbar.dependencies>{{{dependencies}}}</bitbar.dependencies>
# <bitbar.image>{{{image_url}}}</bitbar.image>
# <bitbar.abouturl>{{{about_url}}}</bitbar.abouturl>
#
# REMINDER: You can have the script auto-refresh by changing the filename
#
# {name}.{time}.{ext}
# name - The name of the file
# time - The refresh rate (see below)
# ext - The file extension
#
# For example:
# `date.1m.sh` would refresh every minute.
#
# 10s - ten seconds
# 1m - one minute
# 2h - two hours
# 1d - a day
suppressPackageStartupMessages({
library(magrittr, quietly = TRUE, verbose = FALSE, warn.conflicts = FALSE)

8
man/new_bitbar_script.Rd

@ -13,13 +13,19 @@ new_bitbar_script(
description = "BitBar Plugin Using R",
dependencies = "R",
image_url = "",
about_url = ""
about_url = "",
refresh = ""
)
}
\arguments{
\item{save_as}{full path (including scriptname.R) to where you want the file saved}
\item{title, version, author, github_user, description, dependencies, image_url, about_url}{BitBar metadata passed on to the generator.}
\item{refesh}{if non-blank this will cause the filename to include a refresh hint
in the \code{save_as} filename before the ending \code{.R} so BitBar will run the script
every \code{refresh} period. See \href{https://github.com/matryer/bitbar#configure-the-refresh-time}{Configuring the refresh time}
for more information.}
}
\description{
Helper to get started with a new BitBar {bitbar} script

Loading…
Cancel
Save