diff --git a/startkde/startplasma.cpp b/startkde/startplasma.cpp --- a/startkde/startplasma.cpp +++ b/startkde/startplasma.cpp @@ -179,6 +179,10 @@ // (where correspond to the system and user's configuration // directory. // +// Scripts that belong to the user's configuration directory are sourced *after* +// those belonging to the system directory. For each directory (system and user), +// scripts are sourced in lexical order of their filename. +// // This is where you can define environment variables that will be available to // all KDE programs, so this is where you can run agents using e.g. eval `ssh-agent` // or eval `gpg-agent --daemon`. @@ -190,19 +194,45 @@ void runEnvironmentScripts() { - QStringList scripts; - const auto locations = QStandardPaths::locateAll(QStandardPaths::GenericConfigLocation, QStringLiteral("plasma-workspace/env"), QStandardPaths::LocateDirectory); + const auto locations = QStandardPaths::locateAll(QStandardPaths::GenericConfigLocation, + QStringLiteral("plasma-workspace/env"), QStandardPaths::LocateDirectory); + + QFileInfoList userScripts; + QFileInfoList systemScripts; for (const QString & location : locations) { + // check if location belongs to user's home directory + bool dirIsUser = location.startsWith(QDir::homePath()); + QDir dir(location); const auto dirScripts = dir.entryInfoList({QStringLiteral("*.sh")}); for (const auto script : dirScripts) { - scripts << script.absoluteFilePath(); + if (dirIsUser) { + userScripts << script; + } else { + systemScripts << script; + } } } + + // Lambda used to sort QFileInfo objects by their filename instead of full path + auto compareFileName = [](const QFileInfo a, const QFileInfo b) + -> bool { return a.fileName() < b.fileName(); }; + + QStringList scripts; + // Add all system scripts, sorted lexically by filename + std::sort(systemScripts.begin(), systemScripts.end(), compareFileName); + for (const auto script: systemScripts) { + scripts << script.absoluteFilePath(); + } + // Add all user scripts, sorted lexically by filename + std::sort(userScripts.begin(), userScripts.end(), compareFileName); + for (const auto script: userScripts) { + scripts << script.absoluteFilePath(); + } + sourceFiles(scripts); } - // Mark that full KDE session is running (e.g. Konqueror preloading works only // with full KDE running). The KDE_FULL_SESSION property can be detected by // any X client connected to the same X session, even if not launched