Giter Site home page Giter Site logo

prompt's Introduction

prompt

Dynamic R Prompt

Lifecycle: stable R-CMD-check Codecov test coverage

Set the R prompt dynamically, from a function. The package contains some examples.

Examples

This is prompt_fancy() and it has

  • The status of the last command (success or failure).
  • The amount of memory allocated by the current R process.
  • The name of the R package being developed using devtools.
  • Name of the active git branch.
  • State of the git working tree (needs pushes, pulls, and/or dirty).

A powerline clone, that also shows the system load average and the current working directory.

Installation

Install the package from CRAN, as usual:

install.packages("prompt")

Usage

Use one of the pre-defined prompts, as on the screenshots, or create your own. You can set the prompt in your .Rprofile. Maybe you only want to do this in interactive mode:

if (interactive()) prompt::set_prompt(prompt::prompt_fancy)

or the powerline prompt:

if (interactive()) prompt::set_prompt(prompt::new_prompt_powerline())

License

MIT © Gábor Csárdi

prompt's People

Contributors

gaborcsardi avatar hadley avatar henrikbengtsson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

prompt's Issues

Export more of the git functions

Can you export more of the git functions? That would allow a bit more customisation.e.g.

  • is_git_dir
  • git
  • git_info

Happy to submit a PR.

Thanks

Error message when setting up prompt using {startup}

It might not be a bug with {prompt} but rather an interaction between {prompt} and {startup} (cc'ing @HenrikBengtsson) but if I try to set the prompt from my startup files, I see:

Error in globalCallingHandlers(error = function(err) update_callback(NA,  : 
  should not be called with handlers on the stack
Backtrace:1. ├─[ base::try(...) ] with 4 more calls
  6. ├─[ startup::startup() ] with 12 more calls
 19. └─prompt::set_prompt(prompt::new_prompt_powerline()) .Rprofile.d/interactive=TRUE/IS_ESS!=true.R:2:2
 20.   └─base::globalCallingHandlers(...)

Let me know if more info would be useful (feel free to close this if it's not a bug). Thanks!

RStudio crashes if library(prompt) is in .RProfile

If I change my .Rprofile to only include the line library(prompt) RStudio crashes with the following error:
error

however, if I clear my .Rprofile, and run library(prompt) from the Console, it runs fine.

Session Info:

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0   

Running version 1.2.1335 of RStudio. R_USER is set to a network path (in this case, M:/Documents).

My usual .RProfile loads up some other packages without issue, only prompt causes the crash. Interestingly, if I run R from the command prompt rather than using RStudio having library(prompt) causes no issues, so it may well be that this is not a bug in prompt, but in RStudio.

A bodge to get it to work in RStudio is to have the following .Rprofile

prompt_error_hook <- function() {}
library(prompt)

Which makes me wonder whether the .onLoad is called before the Prompts file is run? Perhaps move the .onX functions to a file named ZZZ.R?

Runtime in prompt_fancy

Hi! I want to see the runtime in prompt_fancy. Now it works only alone in prompt_runtime and I don't know how to add it to my prompt. Can it be done?

browser() on error doesn't work

My .Rprofile:

options(error = utils::recover,
        ...)
...
if (requireNamespace("prompt", quietly = TRUE))
  prompt::set_prompt(prompt::prompt_fancy)

If I comment out the set_prompt() line, and run

fun <- function() stop()
fun()

I end up in the browser() view, as I'd expect. Also if I enter getOption("error"), I get back the recover() function. So far so good.

If I re-enable set_prompt() in my .Rprofile, getOption("error"), it seems like the prompt_error_hook() function is injected. Unfortunately, now the browser() function is no longer called on error. The issue cannot be worked around by temporarily disabling prompt using suspend().

What does solve the problem is setting the error option in my .Rprofile after calling set_prompt().

❯ sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] C/UTF-8/C/C/C/C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] colorout_1.2-0   prettycode_1.0.1 devtools_1.13.5

loaded via a namespace (and not attached):
 [1] compiler_3.5.0     clisymbols_1.2.0   fs_1.2.5           withr_2.1.2
 [5] glue_1.3.0         Rcpp_0.12.18       crayon_1.3.4       memoise_1.1.0
 [9] usethis_1.3.0.9000 memuse_4.0-0       digest_0.6.16      prompt_1.0.0

Temporary disable prompt

It would be useful to be able to temporary disable the prompt prompt, without having to re-enable it using set_prompt(). Why? I just tried to debug a strsplit call and go the following:

198.7 MiB
❯ debug(strsplit)
debugging in: strsplit(.Internal(Sys.getenv(character(), "")), "=", fixed = TRUE)
debug: .Internal(strsplit(x, as.character(split), fixed, perl, useBytes))
Browse[2]> 
[...]

which is triggered by prompt code.

Maybe something like:

198.7 MiB
❯ use_prompt(FALSE)
> debug(strsplit)
[...]
> use_prompt(TRUE)
✔ 198.7 MiB

work in rstudio?

Rstudio version 0.99.875

R version 3.2.2

library(prompt)
set_prompt(prompt_fancy)

rstudio_prompt

It is hard to tell from this, but my cursor is actually above the prompt. Not sure if this is a fault of prompt or crayon.

output of devtools::session_info:

Session info ------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.2.2 (2015-08-14)
 system   x86_64, linux-gnu           
 ui       RStudio (0.99.875)          
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/New_York            
 date     2016-03-02                  

Packages ----------------------------------------------------------------------------------------------------------------------
 package    * version    date       source                             
 clisymbols   1.0.0      2015-06-08 CRAN (R 3.2.2)                     
 crayon       1.3.1      2015-07-13 CRAN (R 3.2.2)                     
 devtools     1.9.1.9000 2016-01-21 local                              
 digest       0.6.9      2016-01-08 CRAN (R 3.2.3)                     
 memoise      1.0.0      2016-01-29 CRAN (R 3.2.2)                     
 parr         3.3.0      2016-03-02 Github (gaborcsardi/parr@441a4b9)  
 prompt     * 1.0.0      2016-03-02 Github (gaborcsardi/prompt@efaba86)

require newer version of ps?

> if (interactive()) prompt::set_prompt(prompt::new_prompt_powerline())
Error : 'ps_loadavg' is not an exported object from 'namespace:ps'
Error: 'ps_loadavg' is not an exported object from 'namespace:ps'

The issue resolved after upgrading ps, but perhaps prompt should explicitly depend on the newest version.

Release prompt 1.0.2

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • revdepcheck::revdep_check(num_workers = 8)
  • Update cran-comments.md
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.