tmuxr v0.1.0

0

Monthly downloads

0th

Percentile

Manage 'tmux'

Create, control, and record 'tmux' sessions, windows, and panes using a pipeable API.

Readme

tmuxr

AppVeyor Build status Travis-CI build status codecov CRAN\_Status\_Badge

Overview

tmuxr is an R package that allows you (1) to manage tmux and (2) to interact with the processes it runs. It features a pipeable API with which you can create, control, and capture tmux sessions, windows, and panes.

Most functions, such as new_session, list_windows, and send_keys are inspired by the commands tmux offers. Other functions, such as attach_window, wait_for_prompt, send_lines are added for convenience. Please note that not all tmux commands have yet been implemented.

Installation

You can install tmuxr from GitHub with:

# install.packages("devtools")
devtools::install_github("datascienceworkshops/tmuxr")

Examples

library(tmuxr)

Bash

s <- new_session(shell_command = "PS1='$ ' bash",
                 prompt = prompts$bash)
wait_for_prompt(s)
send_lines(s, c("seq 100 |",
                "grep 3 |",
                "wc -l ",
                "date"))
capture_pane(s, trim = TRUE)
#> [1] "$ seq 100 |"                  "> grep 3 |"                  
#> [3] "> wc -l"                      "      19"                    
#> [5] "$ date"                       "Thu Nov  9 13:35:52 CET 2017"
kill_session(s)

Run R via Docker

new_session(shell_command = "docker run --rm -it rocker/tidyverse R",
            prompt = prompts$R,
            name = "docker_R") %>%
  send_lines(c("library(tidyverse)",
               "sessionInfo()")) %>%
  capture_pane(as_message = TRUE)
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base
#> 
#> other attached packages:
#> [1] dplyr_0.7.2     purrr_0.2.2.2   readr_1.1.1     tidyr_0.6.3
#> [5] tibble_1.3.3    ggplot2_2.2.1   tidyverse_1.1.1
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_0.12.12     cellranger_1.1.0 compiler_3.4.1   plyr_1.8.4
#>  [5] bindr_0.1        forcats_0.2.0    tools_3.4.1      jsonlite_1.5
#>  [9] lubridate_1.6.0  nlme_3.1-131     gtable_0.2.0     lattice_0.20-35
#> [13] pkgconfig_2.0.1  rlang_0.1.1      psych_1.7.5      parallel_3.4.1
#> [17] haven_1.1.0      bindrcpp_0.2     xml2_1.1.1       stringr_1.2.0
#> [21] httr_1.2.1       hms_0.3          grid_3.4.1       glue_1.1.1
#> [25] R6_2.2.2         readxl_1.0.0     foreign_0.8-69   reshape2_1.4.2
#> [29] modelr_0.1.1     magrittr_1.5     scales_0.4.1     rvest_0.3.2
#> [33] assertthat_0.2.0 mnormt_1.5-5     colorspace_1.3-2 stringi_1.1.5
#> [37] lazyeval_0.2.0   munsell_0.4.3    broom_0.4.2
#> >

Jupyter console

jupyter <- new_session(name = "python",
                       shell_command = "jupyter console",
                       prompt = prompts$jupyter)

jupyter$prompt
#> [1] "^(In \\[[0-9]+\\]| {6,})|$"

jupyter %>%
  wait_for_prompt() %>%
  send_lines(c("def mysum(a, b):",
               "return a + b",
               "",
               "")) %>%
  capture_pane(as_message = TRUE, strip_lonely_prompt = FALSE, trim = TRUE)
#> Jupyter console 5.1.0
#> 
#> Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09)
#> Type "copyright", "credits" or "license" for more information.
#> 
#> IPython 5.3.0 -- An enhanced Interactive Python.
#> ?         -> Introduction and overview of IPython's features.
#> %quickref -> Quick reference.
#> help      -> Python's own help system.
#> object?   -> Details about 'object', use 'object??' for extra details.
#> 
#> 
#> 
#> In [1]: def mysum(a, b):
#>       :     return a + b
#>       :
#>       :

Continue with an existing session

attach_session("python", prompt = prompts$jupyter) %>%
  wait(0.2) %>%
  send_lines("mysum(41, 1)") %>%
  wait(0.2) %>%
  capture_pane(start = 18, as_message = TRUE)
#> In [2]: mysum(41, 1)
#> Out[2]: 42
#> 
#> In [3]:
list_sessions()
#> [[1]]
#> tmuxr session docker_R: 1 windows (created Thu Nov  9 13:35:52 2017) [80x24]
#> [[2]]
#> tmuxr session python: 1 windows (created Thu Nov  9 13:35:54 2017) [80x24]
kill_server()
#> character(0)

License

The tmuxr package is licensed under the MIT License.

Functions in tmuxr

Name Description
has_prompt Is there a prompt pattern associated with a session, window, or pane?
is_installed Is tmux installed?
is_running Is the tmux server running?
kill_server Kill the tmux server.
attach_pane Attach to an existing tmux pane.
attach_session Attach to an existing tmux session.
ends_with_prompt Does the contents of a pane end with prompt?
get_prompt Get the prompt pattern of a session, window or pane.
kill_session Kill a session.
list_panes List panes.
wait Wait.
wait_for_prompt Wait for prompt to appear in session, window or pane.
attach_window Attach to an existing tmux window.
capture_pane Capture contents of a pane.
new_session Create a new tmux session.
pipe_pane Pipe contents of a pane to a shell command.
send_control_c Send the Control C combination to a session, window or pane.
send_enter Send the Enter key to a session, window or pane.
prompts A list of commonly used prompt patterns.
reexports Objects exported from other packages
send_keys Send keys to a session, window, or pane.
rename_session Rename a session.
send_backspace Send the Backspace key to a session, window or pane.
send_lines Send multiple lines to a session, window, or pane.
list_sessions List sessions.
list_windows List windows.
set_prompt Set the prompt pattern of a session, window or pane.
start_server Start the tmux server.
No Results!

Last month downloads

Details

License MIT + file LICENSE
Encoding UTF-8
LazyData true
URL https://github.com/datascienceworkshops/tmuxr
BugReports https://github.com/datascienceworkshops/tmuxr/issues
SystemRequirements tmux
OS_type unix
Collate tmuxr.R server.R session.R window.R pane.R prompt.R send.R
RoxygenNote 6.0.1
NeedsCompilation no
Packaged 2017-11-13 09:16:28 UTC; jeroen
Repository CRAN
Date/Publication 2017-11-13 19:30:44 UTC

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/tmuxr)](http://www.rdocumentation.org/packages/tmuxr)