[icinga-checkins] icinga.org: icinga2/master: Implement history support for 'icinga2 console '

git at icinga.org git at icinga.org
Fri Jul 29 13:52:44 CEST 2016


Module: icinga2
Branch: master
Commit: a02d7d75020bd9963d05ee449fd320836d27e047
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=a02d7d75020bd9963d05ee449fd320836d27e047

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri Jul 29 13:45:16 2016 +0200

Implement history support for 'icinga2 console'

fixes #12234

---

 lib/cli/consolecommand.cpp |   22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/lib/cli/consolecommand.cpp b/lib/cli/consolecommand.cpp
index f3f4fcb..98d120c 100644
--- a/lib/cli/consolecommand.cpp
+++ b/lib/cli/consolecommand.cpp
@@ -193,6 +193,20 @@ int ConsoleCommand::RunScriptConsole(ScriptFrame& scriptFrame, const String& add
 	std::map<String, String> lines;
 	int next_line = 1;
 
+#ifdef HAVE_EDITLINE
+	String homeEnv = getenv("HOME");
+	String historyPath = homeEnv + "/.icinga2_history";
+
+	std::fstream historyfp;
+	historyfp.open(historyPath.CStr(), std::fstream::in);
+
+	String line;
+	while (std::getline(historyfp, line.GetData()))
+		add_history(line.CStr());
+
+	historyfp.close();
+#endif /* HAVE_EDITLINE */
+
 	l_ScriptFrame = &scriptFrame;
 	l_Session = session;
 
@@ -254,7 +268,13 @@ incomplete:
 			if (!cline)
 				break;
 
-			add_history(cline);
+			if (commandOnce.IsEmpty()) {
+				add_history(cline);
+
+				historyfp.open(historyPath.CStr(), std::fstream::out | std::fstream::app);
+				historyfp << cline << "\n";
+				historyfp.close();
+			}
 
 			line = cline;
 



More information about the icinga-checkins mailing list