config subcommand impl.

+ _reve/util_read_config {config_key}
+ _reve/util_write_config {config_key} {value}
+ _reve/util_delete_config {config_key}
+ let shellcheck know what we're sourcing
This commit is contained in:
2024-08-26 22:16:37 +03:00
parent b7e29e8c35
commit cb1b26770a
4 changed files with 55 additions and 3 deletions

View File

@@ -3,6 +3,10 @@
# reve desktop environment framework
# Yigid BALABAN <fyb@fybx.dev> 2024
# VERY CRITICAL: change this if install.sh is updated
reve_installation="$HOME/.local/bin/reve"
reve_config="$HOME/.config/reve"
util_readf () {
local filename=$1
@@ -13,3 +17,28 @@ util_readf () {
return 1
fi
}
util_read_config () {
local config_key=$1
pre_removed_key=${config_key/#base./}
config_path=$( echo "$pre_removed_key" | sed 's/\./\//g' )
util_readf "$reve_config/$config_path"
return $?
}
util_write_config () {
local config_key=$1 new_value=$2
pre_removed_key=${config_key/#base./}
config_path=$( echo "$pre_removed_key" | sed 's/\./\//g' )
mkdir -p "$( dirname "$reve_config/$config_path" )"
echo "$new_value" > "$reve_config/$config_path"
}
util_delete_config () {
local config_key=$1
pre_removed_key=${config_key/#base./}
config_path=$( echo "$pre_removed_key" | sed 's/\./\//g' )
rm "$reve_config/$config_path"
dir=$( dirname "$reve_config/$config_path")
[ -z "$( ls -A "$dir")" ] && rm -r "$dir"
}