File Pre-process-e-custom-command-argument.patch of Package konsole
From a779c8314a7d27bb4691c220f793540e6f84f6c9 Mon Sep 17 00:00:00 2001
From: Maximiliano Curia <maxy@gnuservers.com.ar>
Date: Mon, 19 Dec 2016 22:26:46 +0100
Subject: Pre process the -e custom command argument
Special case parsing of -e, to avoid parsing parameters intended for the
command to be executed.
REVIEW: 129677
---
src/Application.cpp | 39 ++++++++++++++++++++++++++-------------
src/Application.h | 4 +++-
src/main.cpp | 8 ++++++--
3 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/src/Application.cpp b/src/Application.cpp
index 6651fe7..6e8e1ee 100644
--- a/src/Application.cpp
+++ b/src/Application.cpp
@@ -45,7 +45,7 @@
using namespace Konsole;
-Application::Application(QSharedPointer<QCommandLineParser> parser) : m_parser(parser)
+Application::Application(QSharedPointer<QCommandLineParser> parser, const QStringList &customCommand) : m_parser(parser), m_customCommand(customCommand)
{
_backgroundInstance = 0;
}
@@ -115,6 +115,22 @@ void Application::populateCommandLineParser(QCommandLineParser *parser)
parser->addOption(titleOption);
}
+QStringList Application::getCustomCommand(QStringList &args)
+{
+ int i = args.indexOf("-e");
+ QStringList customCommand;
+ if ((0 < i) && (i < (args.size() - 1))) {
+ // -e was specified with at least one extra argument
+ // if -e was specified without arguments, QCommandLineParser will deal
+ // with that
+ args.removeAt(i);
+ while (args.size() > i) {
+ customCommand << args.takeAt(i);
+ }
+ }
+ return customCommand;
+}
+
Application::~Application()
{
SessionManager::instance()->closeAllSessions();
@@ -479,21 +495,16 @@ Profile::Ptr Application::processProfileChangeArgs(Profile::Ptr baseProfile)
}
// run a custom command
- if (m_parser->isSet(QStringLiteral("e"))) {
- QString commandExec = m_parser->value(QStringLiteral("e"));
- QStringList commandArguments;
-
- if (m_parser->positionalArguments().count() == 0 &&
- QStandardPaths::findExecutable(commandExec).isEmpty()) {
+ if (!m_customCommand.isEmpty()) {
+ // Example: konsole -e man ls
+ QString commandExec = m_customCommand[0];
+ QStringList commandArguments(m_customCommand);
+ if ((m_customCommand.size() == 1) &&
+ (QStandardPaths::findExecutable(commandExec).isEmpty())) {
// Example: konsole -e "man ls"
- ShellCommand shellCommand(m_parser->value(QStringLiteral("e")));
+ ShellCommand shellCommand(commandExec);
commandExec = shellCommand.command();
commandArguments = shellCommand.arguments();
- } else {
- // Example: konsole -e man ls
- commandArguments << commandExec;
- for ( int i = 0 ; i < m_parser->positionalArguments().count() ; i++ )
- commandArguments << m_parser->positionalArguments().at(i);
}
if (commandExec.startsWith(QLatin1String("./")))
@@ -551,6 +562,8 @@ void Application::slotActivateRequested (QStringList args, const QString & /*wor
// In the current version it just strips it away
args.prepend(qApp->applicationFilePath());
+ m_customCommand = getCustomCommand(args);
+
// We can't re-use QCommandLineParser instances, it preserves earlier parsed values
QCommandLineParser *parser = new QCommandLineParser;
populateCommandLineParser(parser);
diff --git a/src/Application.h b/src/Application.h
index 8987d78..8ec7ab6 100644
--- a/src/Application.h
+++ b/src/Application.h
@@ -50,9 +50,10 @@ class Application : public QObject
public:
/** Constructs a new Konsole application. */
- Application(QSharedPointer<QCommandLineParser> parser);
+ Application(QSharedPointer<QCommandLineParser> parser, const QStringList &customCommand);
static void populateCommandLineParser(QCommandLineParser *parser);
+ static QStringList getCustomCommand(QStringList &args);
~Application();
@@ -89,6 +90,7 @@ private:
MainWindow* _backgroundInstance;
QSharedPointer<QCommandLineParser> m_parser;
+ QStringList m_customCommand;
};
}
#endif // APPLICATION_H
diff --git a/src/main.cpp b/src/main.cpp
index f4bb5af..fb53560 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -111,9 +111,13 @@ extern "C" int Q_DECL_EXPORT kdemain(int argc, char* argv[])
parser->addHelpOption();
parser->addVersionOption();
about.setupCommandLine(parser.data());
+
+ QStringList args = QStringList(app->arguments());
+ QStringList customCommand = Application::getCustomCommand(args);
+
Application::populateCommandLineParser(parser.data());
- parser->process(*app);
+ parser->process(args);
about.processCommandLine(parser.data());
atexit(deleteQApplication);
@@ -152,7 +156,7 @@ extern "C" int Q_DECL_EXPORT kdemain(int argc, char* argv[])
// If we reach this location, there was no existing copy of Konsole
// running, so create a new instance.
- Application konsoleApp(parser);
+ Application konsoleApp(parser, customCommand);
// The activateRequested() signal is emitted when a second instance
// of Konsole is started.
--
cgit v0.11.2