You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
provs/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Bash.kt

38 lines
1.2 KiB
Kotlin

package org.domaindrivenarchitecture.provs.desktop.infrastructure
import org.domaindrivenarchitecture.provs.framework.core.Prov
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.addTextToFile
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createDir
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.dirExists
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall
import java.io.File
fun Prov.configureBash() = def {
configureBashForUser()
}
fun Prov.configureBashForUser(): ProvResult = def {
val dirname = "~/.bashrc.d"
if(!dirExists(dirname)) {
createDir(dirname)
cmd("chmod 755 " + dirname)
aptInstall("bash-completion screen")
val enhance = """
# source .bashrc.d files
if [ -d ~/.bashrc.d ]; then
for i in ~/.bashrc.d/*.sh; do
if [ -r \$\{i} ]; then
. \\\$\{i}
fi
done
unset i
fi""".trimIndent() + "\n"
addTextToFile(text = enhance, file = File("~/.bashrc"))
} else {
ProvResult(true)
}
}