diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/common/service/placeholder/impl/EnvironmentPlaceholder.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/service/placeholder/impl/EnvironmentPlaceholder.kt new file mode 100644 index 0000000..78a60e5 --- /dev/null +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/common/service/placeholder/impl/EnvironmentPlaceholder.kt @@ -0,0 +1,25 @@ +package com.artemchep.keyguard.common.service.placeholder.impl + +import com.artemchep.keyguard.common.io.IO +import com.artemchep.keyguard.common.io.ioEffect +import com.artemchep.keyguard.common.service.placeholder.Placeholder + +class EnvironmentPlaceholder( +) : Placeholder { + private val regex = "^%(.+)%$".toRegex() + + override fun get( + key: String, + ): IO? = kotlin.run { + val result = regex.matchEntire(key) + if (result != null) { + ioEffect { + val variable = result.groupValues[1] + System.getenv(variable) + } + } else { + // unknown + null + } + } +} diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/screen/VaultViewStateProducer.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/screen/VaultViewStateProducer.kt index 698b756..1c6670d 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/screen/VaultViewStateProducer.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/screen/VaultViewStateProducer.kt @@ -72,6 +72,7 @@ import com.artemchep.keyguard.common.service.placeholder.impl.CipherPlaceholder import com.artemchep.keyguard.common.service.placeholder.impl.CommentPlaceholder import com.artemchep.keyguard.common.service.placeholder.impl.CustomPlaceholder import com.artemchep.keyguard.common.service.placeholder.impl.DateTimePlaceholder +import com.artemchep.keyguard.common.service.placeholder.impl.EnvironmentPlaceholder import com.artemchep.keyguard.common.service.placeholder.impl.TextTransformPlaceholder import com.artemchep.keyguard.common.service.placeholder.impl.UrlPlaceholder import com.artemchep.keyguard.common.service.placeholder.placeholderFormat @@ -474,6 +475,7 @@ fun vaultViewScreenState( CustomPlaceholder(secretOrNull), DateTimePlaceholder(), TextTransformPlaceholder(), + EnvironmentPlaceholder(), ) val extractors = LinkInfoRegistry(linkInfoExtractors) val cipherUris = secretOrNull diff --git a/wiki/PLACEHOLDERS.md b/wiki/PLACEHOLDERS.md index 2f2a92b..230e014 100644 --- a/wiki/PLACEHOLDERS.md +++ b/wiki/PLACEHOLDERS.md @@ -88,6 +88,16 @@ _Example_: https://example.com?user=joe&password=Password1%21 ``` +#### Environmental variables + +System environment variables are supported. +The name of the variable must be enclosed in `%` characters. + +_Example_: +``` +> {%HOME%} +/home/username +``` #### Date-time ##### Local