mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-10-31 15:12:28 +00:00 
			
		
		
		
	Improvement: allow arguments to be passed to the process launched with the terminal.
This commit is contained in:
		
							
								
								
									
										25
									
								
								app/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								app/main.cpp
									
									
									
									
									
								
							| @@ -31,18 +31,27 @@ int main(int argc, char *argv[]) | ||||
|     QStringList args = app.arguments(); | ||||
|     if (args.contains("-h") || args.contains("--help")) { | ||||
|         qDebug() << "Usage: " + args.at(0) + " [--default-settings] [--workdir <dir>] [--program <prog>] [-p|--profile <prof>] [--fullscreen] [-h|--help]"; | ||||
|         qDebug() << "    --default-settings  Run cool-retro-term with the default settings"; | ||||
|         qDebug() << "    --workdir <dir>     Change working directory to 'dir'"; | ||||
|         qDebug() << "    --program <prog>    Run the 'prog' in the new terminal."; | ||||
|         qDebug() << "    --fullscreen        Run cool-retro-term in fullscreen."; | ||||
|         qDebug() << "    -p|--profile <prof> Run cool-retro-term with the given profile."; | ||||
|         qDebug() << "    -h|--help           Print this help."; | ||||
|         qDebug() << "    --verbose           Print additional informations such as profiles and settings."; | ||||
|         qDebug() << "  --default-settings  Run cool-retro-term with the default settings"; | ||||
|         qDebug() << "  --workdir <dir>     Change working directory to 'dir'"; | ||||
|         qDebug() << "  -e <cmd>            Command to execute. This option will catch all following arguments, so use it as the last option."; | ||||
|         qDebug() << "  --fullscreen        Run cool-retro-term in fullscreen."; | ||||
|         qDebug() << "  -p|--profile <prof> Run cool-retro-term with the given profile."; | ||||
|         qDebug() << "  -h|--help           Print this help."; | ||||
|         qDebug() << "  --verbose           Print additional informations such as profiles and settings."; | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     // Manage default command | ||||
|     QStringList cmdList; | ||||
|     if (args.contains("-e")) { | ||||
|         cmdList << args.mid(args.indexOf("-e") + 1); | ||||
|     } | ||||
|     QVariant command(cmdList.empty() ? QVariant() : cmdList[0]); | ||||
|     QVariant commandArgs(cmdList.size() <= 1 ? QVariant() : QVariant(cmdList.mid(1))); | ||||
|     engine.rootContext()->setContextProperty("defaultCmd", command); | ||||
|     engine.rootContext()->setContextProperty("defaultCmdArgs", commandArgs); | ||||
|  | ||||
|     engine.rootContext()->setContextProperty("workdir", getNamedArgument(args, "--workdir", "$HOME")); | ||||
|     engine.rootContext()->setContextProperty("shellProgram", getNamedArgument(args, "--program")); | ||||
|  | ||||
|     // Manage import paths for Linux and OSX. | ||||
|     QStringList importPathList = engine.importPathList(); | ||||
|   | ||||
| @@ -129,9 +129,10 @@ Item{ | ||||
|             appSettings.terminalFontChanged.connect(handleFontChange); | ||||
|  | ||||
|             // Retrieve the variable set in main.cpp if arguments are passed. | ||||
|             if (shellProgram) { | ||||
|                 ksession.setShellProgram(shellProgram); | ||||
|             } else if (!shellProgram && Qt.platform.os === "osx") { | ||||
|             if (defaultCmd) { | ||||
|                 ksession.setShellProgram(defaultCmd); | ||||
|                 ksession.setArgs(defaultCmdArgs); | ||||
|             } else if (!defaultCmd && Qt.platform.os === "osx") { | ||||
|                 // OSX Requires the following default parameters for auto login. | ||||
|                 ksession.setArgs(["-i", "-l"]); | ||||
|             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user