Skip to content

Commit

Permalink
Update command history in r_session$attach()
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Jul 15, 2019
1 parent 9f7665e commit 4031db9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/r-session.R
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ rs_attach <- function(self, private) {
tryCatch({
while (TRUE) {
cmd <- rs__attach_get_input(paste0("RS ", self$get_pid(), " > "))
update_history(cmd)
private$write_for_sure(paste0(cmd, "\n"))
private$report_back(202, "done")
private$attach_wait()
Expand Down
8 changes: 8 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,11 @@ bold <- function(x) {
get("bold", asNamespace("crayon"))(x),
error = function(e) x)
}

update_history <- function(cmd) {
tmp <- tempfile()
on.exit(unlink(tmp, recursive = TRUE))
savehistory(tmp)
cat(cmd, "\n", sep = "", file = tmp, append = TRUE)
loadhistory(tmp)
}

0 comments on commit 4031db9

Please sign in to comment.