ソースを参照

initial commit

master
boB Rudis 4年前
コミット
91cd622254
この署名に対応する既知のキーがデータベースに存在しません GPGキーID: 1D7529BE14E2BBA9
  1. 1
      .Rbuildignore
  2. 17
      DESCRIPTION
  3. 2
      LICENSE
  4. 21
      LICENSE.md
  5. 8
      NAMESPACE
  6. 54
      R/add-entry.R
  7. 11
      R/bitbar-package.R
  8. 43
      R/use-bitbar.R
  9. 11
      R/utils-pipe.R
  10. 3
      R/zzz.R
  11. 44
      inst/templates/bitbar.R
  12. 31
      man/add_entry.Rd
  13. 6
      man/bitbar.Rd
  14. 26
      man/new_bitbar_script.Rd
  15. 12
      man/pipe.Rd

1
.Rbuildignore

@ -19,3 +19,4 @@
^CRAN-RELEASE$
^appveyor\.yml$
^tools$
^LICENSE\.md$

17
DESCRIPTION

@ -1,6 +1,6 @@
Package: bitbar
Type: Package
Title: bitbar title goes here otherwise CRAN checks fail
Title: Craft macOS Menu Bar Applications with Rscript
Version: 0.1.0
Date: 2020-06-16
Authors@R: c(
@ -8,17 +8,22 @@ Authors@R: c(
comment = c(ORCID = "0000-0001-5670-2640"))
)
Maintainer: Bob Rudis <bob@rud.is>
Description: A good description goes here otherwise CRAN checks fail.
Description: 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.
URL: https://git.rud.is/hrbrmstr/bitbar
BugReports: https://git.rud.is/hrbrmstr/bitbar/issues
Encoding: UTF-8
License: AGPL
License: MIT + file LICENSE
Suggests:
covr, tinytest
Imports:
usethis,
magrittr,
clipr,
knitr,
sys
Depends:
R (>= 3.5.0)
Imports:
httr,
jsonlite
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.0

2
LICENSE

@ -0,0 +1,2 @@
YEAR: 2020
COPYRIGHT HOLDER: Bob Rudis

21
LICENSE.md

@ -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.

8
NAMESPACE

@ -1,4 +1,8 @@
# Generated by roxygen2: do not edit by hand
import(httr)
importFrom(jsonlite,fromJSON)
export("%>%")
export(add_entry)
export(add_separator)
export(new_bitbar_script)
importFrom(magrittr,"%>%")
importFrom(usethis,use_template)

54
R/add-entry.R

@ -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")
}

11
R/bitbar-package.R

@ -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
#' @name bitbar
#' @importFrom usethis use_template
#' @keywords internal
#' @author Bob Rudis (bob@@rud.is)
#' @import httr
#' @importFrom jsonlite fromJSON
"_PACKAGE"

43
R/use-bitbar.R

@ -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))
}
}

11
R/utils-pipe.R

@ -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

3
R/zzz.R

@ -0,0 +1,3 @@
.onLoad <- function(libname, pkgname) {
Sys.setenv("CLIPR_ALLOW"=TRUE)
}

44
inst/templates/bitbar.R

@ -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)

31
man/add_entry.Rd

@ -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}
}

6
man/bitbar.Rd

@ -4,9 +4,11 @@
\name{bitbar}
\alias{bitbar}
\alias{bitbar-package}
\title{...}
\title{Craft macOS Menu Bar Applications with Rscript}
\description{
A good description goes here otherwise CRAN checks fail.
Mat Ryer's macOS utility \url{https://getbitbar.com/} enables any
script to become a menu bar application. Tools are provided to make it
easier to craft these scripts.
}
\seealso{
Useful links:

26
man/new_bitbar_script.Rd

@ -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
}

12
man/pipe.Rd

@ -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}
読み込み中…
キャンセル
保存