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:
parent
b7e29e8c35
commit
cb1b26770a
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
testbench.sh
|
1
.shellcheckrc
Normal file
1
.shellcheckrc
Normal file
@ -0,0 +1 @@
|
||||
external-sources=true
|
29
_reve.sh
29
_reve.sh
@ -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"
|
||||
}
|
||||
|
27
reve.sh
27
reve.sh
@ -18,9 +18,8 @@ reve_time_night="$reve_folder/time_night"
|
||||
reve_chores_mode="$rt_script_dir/chores/mode"
|
||||
|
||||
# bring reve utility functions to the context
|
||||
# shellcheck disable=SC1091
|
||||
# shellcheck source=_reve.sh
|
||||
source "$rt_script_dir/_reve" >&/dev/null
|
||||
# shellcheck disable=SC1091
|
||||
(( $? == 1 )) && source "$rt_script_dir/_reve.sh" # looks like we're in dev environment
|
||||
|
||||
util_help () {
|
||||
@ -43,6 +42,7 @@ util_help () {
|
||||
echo "=> Usage"
|
||||
echo "1. reve config get {config_key} get the value stored in file"
|
||||
echo "2. reve config set {config_key} {value} set the value of file"
|
||||
echo "3. reve config rm {config_key} delete the config file"
|
||||
;;
|
||||
update)
|
||||
echo "=> Usage: reve update [chore names...] updates chores from upstream"
|
||||
@ -136,6 +136,27 @@ chores_mode () {
|
||||
done
|
||||
}
|
||||
|
||||
sub_config () {
|
||||
local config_key=$2
|
||||
case "$1" in
|
||||
get)
|
||||
util_read_config "$config_key"
|
||||
;;
|
||||
set)
|
||||
util_write_config "$config_key" "$3"
|
||||
;;
|
||||
rm|delete)
|
||||
util_delete_config "$config_key"
|
||||
;;
|
||||
"")
|
||||
util_help config
|
||||
;;
|
||||
*)
|
||||
echo "[reve] [E] in subcommand config: '$1' is not a valid command"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main () {
|
||||
if (( rt_has_mode_changed == 1 )) || [[ "$in_reason" == "chores_mode" ]]; then
|
||||
chores_mode
|
||||
@ -148,7 +169,7 @@ main () {
|
||||
|
||||
case "$1" in
|
||||
config)
|
||||
sub_config
|
||||
sub_config $2 $3 $4
|
||||
exit 0
|
||||
;;
|
||||
update)
|
||||
|
Loading…
x
Reference in New Issue
Block a user