diff --git a/app/qml/ApplicationSettings.qml b/app/qml/ApplicationSettings.qml index 077c0a4..2c645f6 100644 --- a/app/qml/ApplicationSettings.qml +++ b/app/qml/ApplicationSettings.qml @@ -97,6 +97,8 @@ QtObject{ signal terminalFontChanged(string fontSource, int pixelSize, int lineSpacing, real screenScaling, real fontWidth) + signal initializedSettings() + property Loader fontManager: Loader{ states: [ State { when: rasterization == no_rasterization @@ -463,6 +465,8 @@ QtObject{ fullscreen = true; showMenubar = false; } + + initializedSettings(); } Component.onDestruction: { storeSettings(); diff --git a/app/qml/PreprocessedTerminal.qml b/app/qml/PreprocessedTerminal.qml index f1ecfdb..76803f4 100644 --- a/app/qml/PreprocessedTerminal.qml +++ b/app/qml/PreprocessedTerminal.qml @@ -129,13 +129,17 @@ Item{ kterminal.lineSpacing = lineSpacing; } - Component.onCompleted: { - appSettings.terminalFontChanged.connect(handleFontChange); + function startSession() { + appSettings.initializedSettings.disconnect(startSession); // Retrieve the variable set in main.cpp if arguments are passed. if (defaultCmd) { ksession.setShellProgram(defaultCmd); ksession.setArgs(defaultCmdArgs); + } else if (appSettings.useCustomCommand) { + var args = Utils.tokenizeCommandLine(appSettings.customCommand); + ksession.setShellProgram(args[0]); + ksession.setArgs(args.slice(1)); } else if (!defaultCmd && Qt.platform.os === "osx") { // OSX Requires the following default parameters for auto login. ksession.setArgs(["-i", "-l"]); @@ -147,6 +151,10 @@ Item{ ksession.startShellProgram(); forceActiveFocus(); } + Component.onCompleted: { + appSettings.terminalFontChanged.connect(handleFontChange); + appSettings.initializedSettings.connect(startSession); + } } Component { id: linuxContextMenu diff --git a/app/qml/utils.js b/app/qml/utils.js index ba8ae04..a8e1af0 100644 --- a/app/qml/utils.js +++ b/app/qml/utils.js @@ -21,3 +21,74 @@ function strToColor(s){ var b = parseInt(s.substring(5,7), 16) / 256; return Qt.rgba(r, g, b, 1.0); } + +/* Tokenizes a command into program and arguments, taking into account quoted + * strings and backslashes. + * Based on GLib's tokenizer, used by Gnome Terminal + */ +function tokenizeCommandLine(s){ + var args = []; + var currentToken = ""; + var quoteChar = ""; + var escaped = false; + var nextToken = function() { + args.push(currentToken); + currentToken = ""; + } + var appendToCurrentToken = function(c) { + currentToken += c; + } + + for (var i = 0; i < s.length; i++) { + + // char followed by backslash, append literally + if (escaped) { + escaped = false; + appendToCurrentToken(s[i]); + + // char inside quotes, either close or append + } else if (quoteChar) { + escaped = s[i] === '\\'; + if (quoteChar === s[i]) { + quoteChar = ""; + nextToken(); + } else if (!escaped) { + appendToCurrentToken(s[i]); + } + + // regular char + } else { + escaped = s[i] === '\\'; + switch (s[i]) { + case '\\': + // begin escape + break; + case '\n': + // newlines always delimits + nextToken(); + break; + case ' ': + case '\t': + // delimit on new whitespace + if (currentToken) { + nextToken(); + } + break; + case '\'': + case '"': + // begin quoted section + quoteChar = s[i]; + break; + default: + appendToCurrentToken(s[i]); + } + } + } + + // ignore last token if broken quotes/backslash + if (currentToken && !escaped && !quoteChar) { + nextToken(); + } + + return args; +}