From 4031db9102a5be9bbcfd97fdfeaf48a2b4debd6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Mon, 15 Jul 2019 11:56:22 +0100 Subject: [PATCH] Update command history in r_session$attach() --- R/r-session.R | 1 + R/utils.R | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/R/r-session.R b/R/r-session.R index f6d709d9..6d5fb2a3 100644 --- a/R/r-session.R +++ b/R/r-session.R @@ -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() diff --git a/R/utils.R b/R/utils.R index 22b35965..c90a33ae 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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) +}