Skip to content

Instantly share code, notes, and snippets.

@dragosmg
Forked from gadenbuie/.Rprofile
Created April 1, 2020 08:15
Show Gist options
  • Select an option

  • Save dragosmg/d7a02568bc2541c2e72e2bd61ea9ab15 to your computer and use it in GitHub Desktop.

Select an option

Save dragosmg/d7a02568bc2541c2e72e2bd61ea9ab15 to your computer and use it in GitHub Desktop.
current project and branch in R command prompt
if (interactive()) {
# requires: devtools::install_github("gaborcsardi/prompt")
.prompt_grk <- function(...) {
dir <- if (rstudioapi::hasFun("getActiveProject") &&
!is.null(rstudioapi::getActiveProject())) {
basename(rstudioapi::getActiveProject())
} else {
basename(getwd())
}
if (!prompt:::is_git_dir()) {
return(paste0(dir, " > "))
}
branch <- prompt::git_branch()
col_branch <- if (branch == "master") crayon::cyan else crayon::yellow
paste0(
crayon::silver(dir),
":",
col_branch(prompt::git_branch()),
crayon::red(prompt::git_dirty()),
prompt::git_arrows(),
" > "
)
}
suppressMessages(library(prompt))
set_prompt(.prompt_grk)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment