Last active
February 3, 2020 22:34
-
-
Save dwhdai/caf356c10cd72315647219fa62489302 to your computer and use it in GitHub Desktop.
Garrick's R prompt, slightly modified
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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