Skip to content

Instantly share code, notes, and snippets.

@dwhdai
Last active February 3, 2020 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwhdai/caf356c10cd72315647219fa62489302 to your computer and use it in GitHub Desktop.
Save dwhdai/caf356c10cd72315647219fa62489302 to your computer and use it in GitHub Desktop.
Garrick's R prompt, slightly modified
# Set R prompt to git branch name
# 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(),
" > "
)
}
# Move function call to outside if() statement since this only needs to run once
prompt <- .prompt_grk()
if (interactive()) {
prompt::set_prompt(prompt)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment