diff --git a/src/main.cpp b/src/main.cpp index f9c42b4f..a1f05a85 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,10 +72,13 @@ QTerminalApp * QTerminalApp::m_instance = nullptr; exit(code); } -void parse_args(int argc, char* argv[], QString& workdir, QString & shell_command, out bool& dropMode) +void parse_args(int argc, char* argv[], QString& workdir, QStringList & shell_command, out bool& dropMode) { int next_option; dropMode = false; + for (int i = 0; i < argc; i++) { + qDebug() << "argv[" << i << "] = " << argv[i]; + } do{ next_option = getopt_long(argc, argv, short_options, long_options, nullptr); switch(next_option) @@ -87,13 +90,13 @@ void parse_args(int argc, char* argv[], QString& workdir, QString & shell_comman workdir = QString::fromLocal8Bit(optarg); break; case 'e': - shell_command = QString::fromLocal8Bit(optarg); + shell_command << QString::fromLocal8Bit(optarg); // #15 "Raw" -e params // Passing "raw" params (like konsole -e mcedit /tmp/tmp.txt") is more preferable - then I can call QString("qterminal -e ") + cmd_line in other programs while (optind < argc) { //printf("arg: %d - %s\n", optind, argv[optind]); - shell_command += QLatin1Char(' ') + QString::fromLocal8Bit(argv[optind++]); + shell_command << QString::fromLocal8Bit(argv[optind++]); } break; case 'd': @@ -143,7 +146,8 @@ int main(int argc, char *argv[]) app->registerOnDbus(); #endif - QString workdir, shell_command; + QString workdir; + QStringList shell_command; bool dropMode; parse_args(argc, argv, workdir, shell_command, dropMode); diff --git a/src/terminalconfig.cpp b/src/terminalconfig.cpp index fae007eb..713de7e4 100644 --- a/src/terminalconfig.cpp +++ b/src/terminalconfig.cpp @@ -8,7 +8,7 @@ #include "properties.h" #include "termwidget.h" -TerminalConfig::TerminalConfig(const QString & wdir, const QString & shell) +TerminalConfig::TerminalConfig(const QString & wdir, const QStringList & shell) { m_workingDirectory = wdir; m_shell = shell; @@ -32,20 +32,28 @@ QString TerminalConfig::getWorkingDirectory() return QTerminalApp::Instance()->getWorkingDirectory(); } -QString TerminalConfig::getShell() +QStringList TerminalConfig::getShell() { if (!m_shell.isEmpty()) return m_shell; + + QString shellString; if (!Properties::Instance()->shell.isEmpty()) - return Properties::Instance()->shell; - QByteArray envShell = qgetenv("SHELL"); - if (envShell.constData() != nullptr) { - QString shellString = QString::fromLocal8Bit(envShell); - if (!shellString.isEmpty()) - return shellString; + shellString = Properties::Instance()->shell; + } + else + { + QByteArray envShell = qgetenv("SHELL"); + if (envShell.constData() != NULL) + { + shellString = QString::fromLocal8Bit(envShell); + } } - return QString(); + QStringList ret; + if (!shellString.isEmpty()) + ret << shellString; + return ret; } void TerminalConfig::setWorkingDirectory(const QString &val) @@ -53,7 +61,7 @@ void TerminalConfig::setWorkingDirectory(const QString &val) m_workingDirectory = val; } -void TerminalConfig::setShell(const QString &val) +void TerminalConfig::setShell(const QStringList &val) { m_shell = val; } @@ -98,7 +106,7 @@ TerminalConfig TerminalConfig::fromDbus(const QHash &termArgs) if (termArgs.contains(QLatin1String(DBUS_ARG_SHELL))) { shell = variantToString(termArgs[QLatin1String(DBUS_ARG_SHELL)], shell); } - return TerminalConfig(wdir, shell); + return TerminalConfig(wdir, QStringList() << shell); } #endif diff --git a/src/terminalconfig.h b/src/terminalconfig.h index 5823fae8..004930ff 100644 --- a/src/terminalconfig.h +++ b/src/terminalconfig.h @@ -11,15 +11,15 @@ class TermWidget; class TerminalConfig { public: - TerminalConfig(const QString & wdir, const QString & shell); + TerminalConfig(const QString & wdir, const QStringList & shell); TerminalConfig(const TerminalConfig &cfg); TerminalConfig(); QString getWorkingDirectory(); - QString getShell(); + QStringList getShell(); void setWorkingDirectory(const QString &val); - void setShell(const QString &val); + void setShell(const QStringList &val); void provideCurrentDirectory(const QString &val); #ifdef HAVE_QDBUS @@ -32,7 +32,7 @@ class TerminalConfig // True when QString m_currentDirectory; QString m_workingDirectory; - QString m_shell; + QStringList m_shell; }; -#endif \ No newline at end of file +#endif diff --git a/src/termwidget.cpp b/src/termwidget.cpp index b51a2646..f10558a4 100644 --- a/src/termwidget.cpp +++ b/src/termwidget.cpp @@ -55,16 +55,11 @@ TermWidgetImpl::TermWidgetImpl(TerminalConfig &cfg, QWidget * parent) setWorkingDirectory(cfg.getWorkingDirectory()); - QString shell = cfg.getShell(); + QStringList shell = cfg.getShell(); if (!shell.isEmpty()) { //qDebug() << "Shell program:" << shell; -#if (QT_VERSION >= QT_VERSION_CHECK(5,15,0)) - QStringList parts = shell.split(QRegExp(QStringLiteral("\\s+")), Qt::SkipEmptyParts); -#else - QStringList parts = shell.split(QRegExp(QStringLiteral("\\s+")), QString::SkipEmptyParts); -#endif - //qDebug() << parts; + QStringList parts = shell; setShellProgram(parts.at(0)); parts.removeAt(0); if (parts.count())