Created
February 3, 2020 18:11
-
-
Save gadenbuie/01f3038cc7c56065de15916c52776503 to your computer and use it in GitHub Desktop.
current project and branch in R command prompt
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
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