├── LICENSE ├── .gitignore ├── example.png ├── prompt.png ├── .Rbuildignore ├── NAMESPACE ├── prompt.Rproj ├── DESCRIPTION ├── prompt.svg ├── .travis.yml ├── man └── set_prompt.Rd ├── README.Rmd ├── README.md └── R └── set_prompt.R /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2017 2 | COPYRIGHT HOLDER: ThinkR 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | README.html 5 | -------------------------------------------------------------------------------- /example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThinkR-open/prompt/HEAD/example.png -------------------------------------------------------------------------------- /prompt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThinkR-open/prompt/HEAD/prompt.png -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^Makefile$ 4 | ^README.Rmd$ 5 | ^.travis.yml$ 6 | ^appveyor.yml$ 7 | ^.*\.png$ 8 | ^.*\.svg$ 9 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(expand_prompt) 4 | export(reset_prompt) 5 | export(set_prompt) 6 | importFrom(glue,glue) 7 | importFrom(memoise,memoise) 8 | importFrom(pryr,mem_used) 9 | importFrom(purrr,walk2) 10 | importFrom(rlang,as_function) 11 | importFrom(utils,capture.output) 12 | importFrom(whoami,gh_username) 13 | importFrom(whoami,username) 14 | -------------------------------------------------------------------------------- /prompt.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | QuitChildProcessesOnExit: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | BuildType: Package 17 | PackageUseDevtools: Yes 18 | PackageInstallArgs: --no-multiarch --with-keep.source 19 | PackageRoxygenize: rd,collate,namespace 20 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: prompt 2 | Title: Dynamic Prompt 3 | Version: 1.0.0 4 | Author: Romain François 5 | Maintainer: Romain François 6 | Description: Dynamic Prompt. 7 | License: MIT + file LICENSE 8 | LazyData: true 9 | URL: https://github.com/ThinkRstat/prompt 10 | BugReports: https://github.com/ThinkRstat/prompt/issues 11 | RoxygenNote: 6.0.1.9000 12 | Imports: rlang, 13 | glue, 14 | whoami, 15 | pryr, 16 | utils, 17 | purrr, 18 | memoise 19 | Encoding: UTF-8 20 | -------------------------------------------------------------------------------- /prompt.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | ## Sample .travis.yml file for use with metacran/r-builder 2 | ## See https://github.com/metacran/r-builder for details. 3 | 4 | language: c 5 | sudo: required 6 | 7 | before_install: 8 | - curl -OL https://raw.githubusercontent.com/metacran/r-builder/master/pkg-build.sh 9 | - chmod 755 pkg-build.sh 10 | - ./pkg-build.sh bootstrap 11 | 12 | install: 13 | - ./pkg-build.sh install_deps 14 | 15 | script: 16 | - ./pkg-build.sh run_tests 17 | 18 | after_failure: 19 | - ./pkg-build.sh dump_logs 20 | 21 | notifications: 22 | email: 23 | on_success: change 24 | on_failure: change 25 | 26 | env: 27 | matrix: 28 | - RVERSION=oldrel 29 | - RVERSION=release 30 | - RVERSION=devel 31 | 32 | -------------------------------------------------------------------------------- /man/set_prompt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/set_prompt.R 3 | \name{set_prompt} 4 | \alias{set_prompt} 5 | \alias{set_prompt} 6 | \alias{reset_prompt} 7 | \alias{set_prompt} 8 | \alias{expand_prompt} 9 | \title{Set the dynamic prompt} 10 | \usage{ 11 | set_prompt(fun) 12 | 13 | reset_prompt() 14 | 15 | expand_prompt(fun) 16 | } 17 | \arguments{ 18 | \item{fun}{whatever \code{\link[rlang]{as_function}} can turn into 19 | a function with no parameters} 20 | } 21 | \description{ 22 | Set the dynamic prompt 23 | } 24 | \examples{ 25 | set_prompt( ~"R> " ) 26 | set_prompt( ~paste( format(Sys.time(), "\%H:\%M:\%S"), " > " ) ) 27 | 28 | # example using glue 29 | set_prompt( ~ "{getwd()} >" ) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "prompt" 3 | author: Romain Francois 4 | output: 5 | md_document: 6 | variant: markdown_github 7 | --- 8 | 9 | ```{r, echo=FALSE, print=FALSE} 10 | library("prompt") 11 | ``` 12 | 13 | ![](prompt.png) 14 | 15 | # prompt 16 | 17 | Dynamic Prompt. 18 | 19 | # Usage 20 | 21 | This use `glue` to expand the function passed in, with the follwing bindings available: 22 | 23 | - `t` the current time, in format "%H:%M:%S" 24 | - `v` the version of R 25 | - `V` the version of R, including the svn revision 26 | - `u` the user name 27 | - `g` the github user name 28 | - `m` the memory currently used by R 29 | - `w` the current working directory 30 | 31 | ```{r eval = FALSE} 32 | set_prompt( ~ "{t}> " ) 33 | set_prompt( ~ "{w}> " ) 34 | set_prompt( ~ "[{m}] {t} {w}> ") 35 | ``` 36 | 37 | You can use `expand_prompt` to experiment : 38 | 39 | ```{r} 40 | expand_prompt( ~ "{t}> " ) 41 | expand_prompt( ~ "{w}> " ) 42 | expand_prompt( ~ "[{m}] {t} {w}> ") 43 | ``` 44 | 45 | ## Installation 46 | 47 | ``` 48 | install_github( "ThinkR-open/prompt" ) 49 | ``` 50 | 51 | ## Initial ideas 52 | 53 | in a way that can be configured. Things we might want to display: 54 | 55 | - current time 56 | - memory used `pryr::mem_used` 57 | - current working directory, maybe slightly differently when it's not the directory of the current rstudio project 58 | - are we developping a package ? Do we need to rebuild it ? 59 | - are we sync with github 60 | - R version 61 | - ... 62 | - (please add your own with PR) 63 | 64 | 65 | ## License 66 | 67 | MIT + file LICENSE © 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](prompt.png) 2 | 3 | prompt 4 | ====== 5 | 6 | Dynamic Prompt. 7 | 8 | Usage 9 | ===== 10 | 11 | This use `glue` to expand the function passed in, with the follwing bindings available: 12 | 13 | - `t` the current time, in format "%H:%M:%S" 14 | - `v` the version of R 15 | - `V` the version of R, including the svn revision 16 | - `u` the user name 17 | - `g` the github user name 18 | - `m` the memory currently used by R 19 | - `w` the current working directory 20 | 21 | ``` r 22 | set_prompt( ~ "{t}> " ) 23 | set_prompt( ~ "{w}> " ) 24 | set_prompt( ~ "[{m}] {t} {w}> ") 25 | ``` 26 | 27 | You can use `expand_prompt` to experiment : 28 | 29 | ``` r 30 | expand_prompt( ~ "{t}> " ) 31 | ``` 32 | 33 | ## 11:39:42> 34 | 35 | ``` r 36 | expand_prompt( ~ "{w}> " ) 37 | ``` 38 | 39 | ## /Users/romain/git/prompt> 40 | 41 | ``` r 42 | expand_prompt( ~ "[{m}] {t} {w}> ") 43 | ``` 44 | 45 | ## [36 MB] 11:39:42 /Users/romain/git/prompt> 46 | 47 | Installation 48 | ------------ 49 | 50 | install_github( "ThinkR-open/prompt" ) 51 | 52 | Initial ideas 53 | ------------- 54 | 55 | in a way that can be configured. Things we might want to display: 56 | 57 | - current time 58 | - memory used `pryr::mem_used` 59 | - current working directory, maybe slightly differently when it's not the directory of the current rstudio project 60 | - are we developping a package ? Do we need to rebuild it ? 61 | - are we sync with github 62 | - R version 63 | - ... 64 | - (please add your own with PR) 65 | 66 | License 67 | ------- 68 | 69 | MIT + file LICENSE © 70 | -------------------------------------------------------------------------------- /R/set_prompt.R: -------------------------------------------------------------------------------- 1 | 2 | #' Set the dynamic prompt 3 | #' 4 | #' @param fun whatever \code{\link[rlang]{as_function}} can turn into 5 | #' a function with no parameters 6 | #' 7 | #' @examples 8 | #' set_prompt( ~"R> " ) 9 | #' set_prompt( ~paste( format(Sys.time(), "%H:%M:%S"), " > " ) ) 10 | #' 11 | #' # example using glue 12 | #' set_prompt( ~ "{getwd()} >" ) 13 | #' 14 | #' @importFrom purrr walk2 15 | #' @importFrom rlang as_function 16 | #' @importFrom glue glue 17 | #' @importFrom whoami username gh_username 18 | #' @importFrom pryr mem_used 19 | #' @importFrom utils capture.output 20 | #' @importFrom memoise memoise 21 | #' @export 22 | set_prompt <- function( fun ){ 23 | removeTaskCallback("prompt::prompt") 24 | invisible(addTaskCallback( function(expr, value, ok, visible){ 25 | options( prompt = expand_prompt(fun) ) 26 | TRUE 27 | }, name = "prompt::prompt" )) 28 | } 29 | 30 | #' @export 31 | #' @name set_prompt 32 | reset_prompt <- function(){ 33 | options( prompt = "> " ) 34 | invisible( removeTaskCallback("prompt::prompt") ) 35 | } 36 | 37 | 38 | #' @export 39 | #' @name set_prompt 40 | expand_prompt <- function( fun ){ 41 | f <- if( is.character(fun) ) { 42 | function() fun 43 | } else { 44 | as_function(fun) 45 | } 46 | glue(f()) 47 | } 48 | 49 | .gh_username <- memoise(function(){ 50 | gh_username(fallback = "") 51 | }) 52 | .username <- memoise(function(){ 53 | username(fallback = "" ) 54 | }) 55 | bindings <- list( 56 | t = ~format( Sys.time(), "%H:%M:%S" ), 57 | v = ~paste(version$major, version$minor, sep="."), 58 | V = ~paste0(version$major, ".", version$minor, "~", version[["svn rev"]]), 59 | u = ~.username(), 60 | g = ~.gh_username(), 61 | m = ~capture.output(print(mem_used())), 62 | w = ~getwd() 63 | ) 64 | here <- environment() 65 | walk2( names(bindings), bindings, ~makeActiveBinding(.x, as_function(.y), here )) 66 | --------------------------------------------------------------------------------