Skip to content

Instantly share code, notes, and snippets.

@shalva97
Last active December 25, 2023 14:50
Show Gist options
  • Save shalva97/a705590f2c0e309374cccc7f6bd667cb to your computer and use it in GitHub Desktop.
Save shalva97/a705590f2c0e309374cccc7f6bd667cb to your computer and use it in GitHub Desktop.
fun main() {
val prefix = "kwriteconfig5 --file \$HOME/.config/kde.org/UserFeedback.org.kde.plasmashell.conf"
val config = """
[Greeter][Wallpaper][org.kde.image][General]
Image=file:///home/shalva/Pictures/lock-screen-wallpaper.jpg
""".trimIndent()
var configCommand = StringBuilder()
var groupCommand = ""
config.lines().filter { it.isNotEmpty() }.forEach {
if (it.startsWith("[")) {
groupCommand = ""
it.replace("]", "")
.split("[")
.filter { it.isNotEmpty() }
.forEach { group ->
groupCommand += "--group \"$group\" "
}
} else {
("$prefix $groupCommand--key \"" + it.split("=")
.joinToString("\" \"").plus("\"\n")).run(configCommand::append)
}
}
print(configCommand)
}
@shalva97
Copy link
Author

shalva97 commented May 12, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment