Created
August 22, 2012 16:17
-
-
Save hadley/3427128 to your computer and use it in GitHub Desktop.
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
library(memoise) | |
library(stringr) | |
git_prompt <- function() { | |
git <- find_git() | |
if (is.null(git)) stop("Git not installed", call. = FALSE) | |
if (!in_git_repo(git)) stop("Not in git repo", call. = FALSE) | |
update <- function(...) update_prompt(git) | |
addTaskCallback(update, name = "git") | |
update() | |
invisible(TRUE) | |
} | |
find_git <- memoise(function() { | |
if (on_path("git")) return("git") | |
if (on_path("git.exe")) return("git") | |
NULL | |
}) | |
update_prompt <- function(git = find_git()) { | |
if (in_git_repo()) { | |
prompt <- paste("(", git_branch(git), ")", | |
if (is_dirty(git)) "*", "> ", sep = "") | |
} else { | |
prompt <- "> " | |
} | |
options(prompt = prompt) | |
invisible(TRUE) | |
} | |
git_branch <- function(git = find_git()) { | |
system2(git, "symbolic-ref --short -q HEAD", stdout = TRUE, stderr = FALSE) | |
} | |
is_dirty <- function(git = find_git()) { | |
system2(git, "diff-index HEAD --quiet", stdout = FALSE) == 1 | |
} | |
in_git_repo <- function(git = find_git()) { | |
system2(git, "rev-parse", stdout = FALSE, stderr = FALSE) == 0 | |
} |
Is there any plans to put this into the devtools
package? That would be kinda cool.
library(devtools)
git_prompt()
on_path
doesn't appear to be a part of the devtools package anymore. Has it been moved to another package? Is there an alternative function that can be used?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does on_path() require devtools?