]> granicus.if.org Git - icinga2/commitdiff
Implement history support for 'icinga2 console'
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 29 Jul 2016 11:45:16 +0000 (13:45 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 29 Jul 2016 11:45:16 +0000 (13:45 +0200)
fixes #12234

lib/cli/consolecommand.cpp

index f3f4fcbccea5f4585b0389655475384e497b9cd5..98d120cf9a9362f913f358d43c8ad317fe2939b0 100644 (file)
@@ -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;