boB Rudis
4 years ago
15 changed files with 276 additions and 14 deletions
@ -0,0 +1,2 @@ |
|||||
|
YEAR: 2020 |
||||
|
COPYRIGHT HOLDER: Bob Rudis |
@ -0,0 +1,21 @@ |
|||||
|
# MIT License |
||||
|
|
||||
|
Copyright (c) 2020 Bob Rudis |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in all |
||||
|
copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
|
SOFTWARE. |
@ -1,4 +1,8 @@ |
|||||
# Generated by roxygen2: do not edit by hand |
# Generated by roxygen2: do not edit by hand |
||||
|
|
||||
import(httr) |
export("%>%") |
||||
importFrom(jsonlite,fromJSON) |
export(add_entry) |
||||
|
export(add_separator) |
||||
|
export(new_bitbar_script) |
||||
|
importFrom(magrittr,"%>%") |
||||
|
importFrom(usethis,use_template) |
||||
|
@ -0,0 +1,54 @@ |
|||||
|
#' Add an entry to the menu |
||||
|
#' |
||||
|
#' Use `add_separator()` to add a separator line and `add_entry()` to make new |
||||
|
#' menubar entries. |
||||
|
#' |
||||
|
#' @param text to display. See `type`. |
||||
|
#' @param type type of entry. |
||||
|
#' - `direct` has no dashes prefix and all output goes directly to the menubar. The first use of `direct` will set the menubar title. |
||||
|
#' - `submenu` uses `level` repeats of `--` to put these items in submenus |
||||
|
#' @param level used with `submenu` option of `type` |
||||
|
#' @param named BitBar entry parameters. See `References`. |
||||
|
#' @references [BitBar Plugin API Reference](https://github.com/matryer/bitbar#writing-plugins) |
||||
|
#' @export |
||||
|
add_entry <- function(text, type = c("direct", "submenu"), level=1, ...) { |
||||
|
|
||||
|
type <- match.arg(type, c("direct", "submenu")) |
||||
|
|
||||
|
type %>% |
||||
|
switch( |
||||
|
direct = text, |
||||
|
submenu = sprintf("%s%s", paste0(rep("--", level), collapse=""), text) |
||||
|
) -> entry |
||||
|
|
||||
|
params <- "" |
||||
|
|
||||
|
p <- list(...) |
||||
|
|
||||
|
if (length(p) > 0) { |
||||
|
|
||||
|
sapply(names(p), function(name) { |
||||
|
value <- p[[name]] |
||||
|
if (is.logical(value)) { |
||||
|
value <- tolower(as.character(value)) |
||||
|
} else if (!is.character(value)) { |
||||
|
value <- toString(value) |
||||
|
} |
||||
|
sprintf("%s=%s", name, value) |
||||
|
}) -> params |
||||
|
|
||||
|
params <- paste0(params, collapse=" ") |
||||
|
|
||||
|
} |
||||
|
|
||||
|
if (nchar(params) > 0) params <- sprintf(" | %s", params) |
||||
|
|
||||
|
cat(entry, params, "\n", sep = "") |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#' @rdname add_entry |
||||
|
#' @export |
||||
|
add_separator <- function() { |
||||
|
cat("---\n") |
||||
|
} |
@ -1,9 +1,12 @@ |
|||||
#' ... |
#' Craft macOS Menu Bar Applications with Rscript |
||||
#' |
#' |
||||
|
#' Mat Ryer's macOS utility <https://getbitbar.com/> enables any |
||||
|
#' script to become a menu bar application. Tools are provided to make it |
||||
|
#' easier to craft these scripts. |
||||
|
#' |
||||
#' @md |
#' @md |
||||
#' @name bitbar |
#' @name bitbar |
||||
|
#' @importFrom usethis use_template |
||||
#' @keywords internal |
#' @keywords internal |
||||
#' @author Bob Rudis (bob@@rud.is) |
#' @author Bob Rudis (bob@@rud.is) |
||||
#' @import httr |
|
||||
#' @importFrom jsonlite fromJSON |
|
||||
"_PACKAGE" |
"_PACKAGE" |
||||
|
@ -0,0 +1,43 @@ |
|||||
|
#' Helper to get started with a new BitBar {bitbar} script |
||||
|
#' |
||||
|
#' @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. |
||||
|
#' @export |
||||
|
new_bitbar_script <- function(save_as, |
||||
|
title = "Script Title", |
||||
|
version = "1.0", |
||||
|
author = Sys.info()[["user"]], |
||||
|
github_user = author, |
||||
|
description = "BitBar Plugin Using R", |
||||
|
dependencies = "R", |
||||
|
image_url = "", |
||||
|
about_url = "") { |
||||
|
|
||||
|
usethis:::render_template( |
||||
|
template = "bitbar.R", |
||||
|
package = "bitbar", |
||||
|
data = list( |
||||
|
title = title, |
||||
|
mb_title = title, |
||||
|
version = version, |
||||
|
author = author, |
||||
|
github_user = github_user, |
||||
|
description = description, |
||||
|
dependencies = dependencies, |
||||
|
image_url = image_url, |
||||
|
about_url = about_url |
||||
|
) |
||||
|
) -> rendered_template |
||||
|
|
||||
|
writeLines(rendered_template, con = path.expand(save_as)) |
||||
|
|
||||
|
Sys.chmod(path.expand(save_as), "0755") |
||||
|
|
||||
|
if (rstudioapi::isAvailable() && rstudioapi::hasFun("navigateToFile")) { |
||||
|
rstudioapi::navigateToFile(path.expand(save_as)) |
||||
|
} else { |
||||
|
utils::file.edit(path.expand(save_as)) |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
#' Pipe operator |
||||
|
#' |
||||
|
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. |
||||
|
#' |
||||
|
#' @name %>% |
||||
|
#' @rdname pipe |
||||
|
#' @keywords internal |
||||
|
#' @export |
||||
|
#' @importFrom magrittr %>% |
||||
|
#' @usage lhs \%>\% rhs |
||||
|
NULL |
@ -0,0 +1,3 @@ |
|||||
|
.onLoad <- function(libname, pkgname) { |
||||
|
Sys.setenv("CLIPR_ALLOW"=TRUE) |
||||
|
} |
@ -0,0 +1,44 @@ |
|||||
|
#!/Library/Frameworks/R.framework/Resources/bin/Rscript --default-packages=base,tools,utils,stats,methods |
||||
|
# |
||||
|
# <bitbar.title>{{{title}}}</bitbar.title> |
||||
|
# <bitbar.version>{{{version}}}</bitbar.version> |
||||
|
# <bitbar.author>{{{author}}}</bitbar.author> |
||||
|
# <bitbar.author.github>{{{github_user}}}</bitbar.author.github> |
||||
|
# <bitbar.desc>{{{description}}}</bitbar.desc> |
||||
|
# <bitbar.dependencies>{{{dependencies}}}</bitbar.dependencies> |
||||
|
# <bitbar.image>{{{image_url}}}</bitbar.image> |
||||
|
# <bitbar.abouturl>{{{about_url}}}</bitbar.abouturl> |
||||
|
|
||||
|
suppressPackageStartupMessages({ |
||||
|
library(magrittr, quietly = TRUE, verbose = FALSE, warn.conflicts = FALSE) |
||||
|
library(clipr, quietly = TRUE, verbose = FALSE, warn.conflicts = FALSE) |
||||
|
library(sys, quietly = TRUE, verbose = FALSE, warn.conflicts = FALSE) |
||||
|
library(bitbar, quietly = TRUE, verbose = FALSE, warn.conflicts = FALSE) |
||||
|
# other library() calls here |
||||
|
}) |
||||
|
|
||||
|
add_entry("{{{title}}}") # this will be the menubar title |
||||
|
|
||||
|
add_separator() |
||||
|
|
||||
|
add_entry(":mushroom: color!", color="#ff0000") # color! |
||||
|
|
||||
|
add_entry("R-project…", href="https://r-project.org/") # clickable URL |
||||
|
|
||||
|
add_separator() |
||||
|
|
||||
|
add_entry("Somewhere") # this will be the submenu entry point |
||||
|
add_entry("Beyond the sea", type = "submenu") |
||||
|
add_entry("Sea", type = "submenu") # this will be a submenu of the submenu |
||||
|
add_entry("Under the Sea", type = "submenu", level = 2) |
||||
|
|
||||
|
add_separator() |
||||
|
|
||||
|
add_entry("What's on your clipboard?") |
||||
|
add_entry(read_clip(), font="Monaco") |
||||
|
|
||||
|
# Keep at end of script --------------------------------------------------- |
||||
|
|
||||
|
add_separator() |
||||
|
|
||||
|
add_entry("Refresh", refresh=TRUE) |
@ -0,0 +1,31 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/add-entry.R |
||||
|
\name{add_entry} |
||||
|
\alias{add_entry} |
||||
|
\alias{add_separator} |
||||
|
\title{Add an entry to the menu} |
||||
|
\usage{ |
||||
|
add_entry(text, type = c("direct", "output", "menu", "submenu"), ...) |
||||
|
|
||||
|
add_separator() |
||||
|
} |
||||
|
\arguments{ |
||||
|
\item{text}{to display. See \code{type}.} |
||||
|
|
||||
|
\item{type}{type of entry. |
||||
|
\itemize{ |
||||
|
\item \code{direct} has no dashes prefix and all output goes directly to the menubar. The first use of \code{direct} will set the menubar title. |
||||
|
\item \code{output} uses \verb{---}, |
||||
|
\item \code{menu} uses \verb{--}, |
||||
|
\item \code{submenu} uses \verb{----} |
||||
|
}} |
||||
|
|
||||
|
\item{named}{BitBar entry parameters. See \code{References}.} |
||||
|
} |
||||
|
\description{ |
||||
|
Use \code{add_separator()} to add a separator line and \code{add_entry()} to make new |
||||
|
menubar entries. |
||||
|
} |
||||
|
\references{ |
||||
|
\href{https://github.com/matryer/bitbar#writing-plugins}{BitBar Plugin API Reference} |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/use-bitbar.R |
||||
|
\name{new_bitbar_script} |
||||
|
\alias{new_bitbar_script} |
||||
|
\title{Helper to get started with a new BitBar {bitbar} script} |
||||
|
\usage{ |
||||
|
new_bitbar_script( |
||||
|
save_as, |
||||
|
title = "Script Title", |
||||
|
version = "1.0", |
||||
|
author = Sys.info()[["user"]], |
||||
|
github_user = author, |
||||
|
description = "BitBar Plugin Using R", |
||||
|
dependencies = "R", |
||||
|
image_url = "", |
||||
|
about_url = "" |
||||
|
) |
||||
|
} |
||||
|
\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.} |
||||
|
} |
||||
|
\description{ |
||||
|
Helper to get started with a new BitBar {bitbar} script |
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/utils-pipe.R |
||||
|
\name{\%>\%} |
||||
|
\alias{\%>\%} |
||||
|
\title{Pipe operator} |
||||
|
\usage{ |
||||
|
lhs \%>\% rhs |
||||
|
} |
||||
|
\description{ |
||||
|
See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. |
||||
|
} |
||||
|
\keyword{internal} |
Loading…
Reference in new issue