]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/terminal/terminalpanel.cpp
Use \r to terminate command in integrated terminal
[dolphin.git] / src / panels / terminal / terminalpanel.cpp
index d87ae3b1e84c6f469017ea001fa4dc445f19f398..a9c61768b0d72d7c8fe05b1bc5e805cabea9b6f6 100644 (file)
@@ -9,7 +9,6 @@
 #include <KActionCollection>
 #include <KIO/DesktopExecParser>
 #include <KIO/Job>
-#include <KIO/JobUiDelegate>
 #include <KJobWidgets>
 #include <KLocalizedString>
 #include <KMessageWidget>
@@ -25,7 +24,6 @@
 #include <QAction>
 #include <QDesktopServices>
 #include <QDir>
-#include <QLabel>
 #include <QShowEvent>
 #include <QTimer>
 #include <QVBoxLayout>
@@ -241,18 +239,10 @@ void TerminalPanel::sendCdToTerminal(const QString& dir, HistoryPolicy addToHist
         return;
     }
 
-#ifndef Q_OS_WIN
-    if (!m_clearTerminal) {
-        // The TerminalV2 interface does not provide a way to delete the
-        // current line before sending a new input. This is mandatory,
-        // otherwise sending a 'cd x' to a existing 'rm -rf *' might
-        // result in data loss. As workaround SIGINT is sent.
-        const int processId = m_terminal->terminalProcessId();
-        if (processId > 0) {
-            kill(processId, SIGINT);
-        }
-    }
-#endif
+    // Send prior Ctrl-E, Ctrl-U to ensure the line is empty. This is
+    // mandatory, otherwise sending a 'cd x\n' to a prompt with 'rm -rf *'
+    // would result in data loss.
+    m_terminal->sendInput(QStringLiteral("\x05\x15"));
 
     // We want to ignore the currentDirectoryChanged(QString) signal, which we will receive after
     // the directory change, because this directory change is not caused by a "cd" command that the
@@ -261,10 +251,10 @@ void TerminalPanel::sendCdToTerminal(const QString& dir, HistoryPolicy addToHist
     if (addToHistory == HistoryPolicy::AddToHistory)
         m_sendCdToTerminalHistory.enqueue(QDir(dir).canonicalPath());
 
-    m_terminal->sendInput(" cd " + KShell::quoteArg(dir) + '\n');
+    m_terminal->sendInput(" cd " + KShell::quoteArg(dir) + '\r');
 
     if (m_clearTerminal) {
-        m_terminal->sendInput(QStringLiteral(" clear\n"));
+        m_terminal->sendInput(QStringLiteral(" clear\r"));
         m_clearTerminal = false;
     }
 }