Compare commits

..

No commits in common. "cb1b26770a44bc72bed39822e837d26c65707d05" and "f91691faaef84275e20663a002c98ae1ece786a9" have entirely different histories.

4 changed files with 56 additions and 120 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
testbench.sh

View File

@ -1 +0,0 @@
external-sources=true

View File

@ -3,10 +3,6 @@
# reve desktop environment framework # reve desktop environment framework
# Yigid BALABAN <fyb@fybx.dev> 2024 # 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 () { util_readf () {
local filename=$1 local filename=$1
@ -17,28 +13,3 @@ util_readf () {
return 1 return 1
fi 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"
}

115
reve.sh
View File

@ -7,6 +7,17 @@ in_desktop_mode=""
in_reason="" in_reason=""
in_chore_name="" in_chore_name=""
SHORTOPTS="h,m:r:c:w,"
LONGOPTS="help,mode:,reason:,chore:,where"
PARSED_OPTS=$(getopt --options $SHORTOPTS --longoptions $LONGOPTS --name "$0" -- "$@")
if [[ $? -ne 0 ]]; then
echo "Failed to parse options."
exit 1
fi
eval set -- "$PARSED_OPTS"
rt_script_dir=$(realpath "$(dirname "$0")") rt_script_dir=$(realpath "$(dirname "$0")")
rt_has_mode_changed=0 rt_has_mode_changed=0
@ -17,40 +28,15 @@ reve_time_night="$reve_folder/time_night"
reve_chores_mode="$rt_script_dir/chores/mode" reve_chores_mode="$rt_script_dir/chores/mode"
# bring reve utility functions to the context source "$rt_script_dir/_reve"
# shellcheck source=_reve.sh
source "$rt_script_dir/_reve" >&/dev/null
(( $? == 1 )) && source "$rt_script_dir/_reve.sh" # looks like we're in dev environment
util_help () { util_help () {
local command="$1" echo "Usage: $0 [options]"
echo "Options:"
case $command in echo "desktop_mode (-m, --mode): dark, light"
reve|'') echo "reason (-r, --reason): time, network"
echo "=> Usage: reve [command] OR reve [subcommand] [command]" echo "chore (-c, --chore): chore_name"
echo "== Commands ==" echo "where (-w, --where): returns where reve's installed"
echo "mode {desktop_mode} sets desktop mode, accepts 'dark' or 'light'"
echo "reason {reason} run reve with reason, accepts 'network' or 'time'"
echo "chore {chore_name} run a single chore, accepts chore name"
echo "where returns where reve's installed"
echo "help [subcommand] shows help message"
echo "== Subcommands =="
echo "1. config gets/sets configuration values"
echo "2. update updates chores"
;;
config)
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"
echo "== Details =="
echo "Updates all chores present on your configuration if nothing is given. The"
echo "chore names must be space delimited."
;;
esac
} }
util_mkdirs () { util_mkdirs () {
@ -136,27 +122,6 @@ chores_mode () {
done 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 () { main () {
if (( rt_has_mode_changed == 1 )) || [[ "$in_reason" == "chores_mode" ]]; then if (( rt_has_mode_changed == 1 )) || [[ "$in_reason" == "chores_mode" ]]; then
chores_mode chores_mode
@ -167,42 +132,44 @@ main () {
fi fi
} }
case "$1" in while true; do
config) case "$1" in
sub_config $2 $3 $4 -h|--help)
util_help
exit 0 exit 0
;; ;;
update) -m|--mode)
sub_update in_desktop_mode="$2"
exit 0 shift 2
;; ;;
help) -r|--reason)
util_help "$2" in_reason="$2"
exit 0 shift 2
;; ;;
where) -c|--chore)
in_chore_name="$2"
shift 2
;;
-w|--where)
dirname "$( which reve )" dirname "$( which reve )"
exit 0 exit 0
;; ;;
shell-completion) --shell-completion)
in_shell_comp="$2" in_shell_comp="$2"
shift 2
f_shell_completion f_shell_completion
exit 0 exit 0
;; ;;
mode) --)
in_desktop_mode="$2" shift
;; break
reason)
in_reason="$2"
;;
chore)
in_chore_name="$2"
;; ;;
*) *)
echo "Invalid command or subcommand: $1" echo "Invalid option: $1"
exit 1 exit 1
;; ;;
esac esac
done
prepare prepare
main main