simplified and refactored chore/single chore workflow
This commit is contained in:
parent
6c8d80f1a8
commit
c356b1765b
4
_reve.sh
4
_reve.sh
@ -51,8 +51,8 @@ util_delete_config() {
|
|||||||
util_run_chore() {
|
util_run_chore() {
|
||||||
local chore_path="$reve_installation/chores/$1"
|
local chore_path="$reve_installation/chores/$1"
|
||||||
if [ -x "$chore_path.sh" ]; then
|
if [ -x "$chore_path.sh" ]; then
|
||||||
error I "util_run_chore" "Running single chore: $(basename "$1")"
|
error I "util_run_chore" "Running chore: $(basename "$1")"
|
||||||
bash "$chore_path.sh"
|
REVE_FOLDER="$reve_config" RV_CURRENT_MODE=$2 bash "$chore_path.sh"
|
||||||
else
|
else
|
||||||
error E "util_run_chore" "$chore_path is not executable"
|
error E "util_run_chore" "$chore_path is not executable"
|
||||||
fi
|
fi
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
|
||||||
# reve desktop environment framework
|
# reve desktop environment framework
|
||||||
# Yigid BALABAN <fyb@fybx.dev> 2024
|
# Yigid BALABAN <fyb@fybx.dev> 2024
|
||||||
@ -8,38 +8,29 @@
|
|||||||
# name swww_single.sh
|
# name swww_single.sh
|
||||||
# desc changes the background depending on the desktop_mode
|
# desc changes the background depending on the desktop_mode
|
||||||
# vars bg_dark, bg_light
|
# vars bg_dark, bg_light
|
||||||
|
# reload asus_kbd_light.sh
|
||||||
|
|
||||||
if ! command -v swww &>/dev/null; then
|
if ! command -v swww &>/dev/null; then
|
||||||
echo "swww is not installed. Please install it and try again."
|
echo "swww is not installed. Please install it and try again."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
reve_folder="$HOME/.config/reve"
|
bg_dark="$REVE_FOLDER/chore/bg_dark"
|
||||||
reve_desktop_mode="$reve_folder/desktop_mode"
|
bg_light="$REVE_FOLDER/chore/bg_light"
|
||||||
bg_dark="$reve_folder/chore/bg_dark"
|
|
||||||
bg_light="$reve_folder/chore/bg_light"
|
|
||||||
|
|
||||||
util_readf () {
|
source "$(reve where)/_reve"
|
||||||
local filename=$1
|
|
||||||
|
|
||||||
if [[ -f "$filename" ]]; then
|
|
||||||
cat "$filename"
|
|
||||||
else
|
|
||||||
echo "util_readf: File not found: $filename" >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
current_mode=$( util_readf "$reve_desktop_mode" )
|
|
||||||
types=("left" "right" "top" "bottom" "wipe" "wave" "grow" "outer")
|
types=("left" "right" "top" "bottom" "wipe" "wave" "grow" "outer")
|
||||||
ltypes=${#types[@]}
|
ltypes=${#types[@]}
|
||||||
rindex=$((RANDOM % ltypes))
|
rindex=$((RANDOM % ltypes))
|
||||||
rtype=${types[rindex]}
|
rtype=${types[rindex]}
|
||||||
|
|
||||||
if [[ $current_mode == "dark" ]]; then
|
if [[ $RV_CURRENT_MODE == "dark" ]]; then
|
||||||
swww img --transition-type "$rtype" --transition-pos 1,1 --transition-step 90 "$bg_dark"
|
swww img --transition-type "$rtype" --transition-pos 1,1 --transition-step 90 "$bg_dark"
|
||||||
notify-send --urgency=low --expire-time=1450 --icon="$bg_dark" --app-name="reve: swww_single" "Wallpaper changed" "Wallpaper changed and saved on dark mode."
|
notify-send --urgency=low --expire-time=1450 --icon="$bg_dark" --app-name="reve: swww_single" "Wallpaper changed" "Wallpaper changed and saved on dark mode."
|
||||||
else
|
else
|
||||||
swww img --transition-type "$rtype" --transition-pos 1,1 --transition-step 90 "$bg_light"
|
swww img --transition-type "$rtype" --transition-pos 1,1 --transition-step 90 "$bg_light"
|
||||||
notify-send --urgency=low --expire-time=1450 --icon="$bg_light" --app-name="reve: swww_single" "Wallpaper changed" "Wallpaper changed and saved on light mode."
|
notify-send --urgency=low --expire-time=1450 --icon="$bg_light" --app-name="reve: swww_single" "Wallpaper changed" "Wallpaper changed and saved on light mode."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
reload misc/asus_kbd_light.sh
|
||||||
|
79
reve.sh
79
reve.sh
@ -3,17 +3,19 @@
|
|||||||
# reve desktop environment framework
|
# reve desktop environment framework
|
||||||
# Yigid BALABAN <fyb@fybx.dev> 2024
|
# Yigid BALABAN <fyb@fybx.dev> 2024
|
||||||
|
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
# SC2086 is disabled here, but all user inputs must be quoted
|
||||||
|
|
||||||
in_desktop_mode=""
|
in_desktop_mode=""
|
||||||
in_reason=""
|
in_reason=""
|
||||||
in_chore_name=""
|
in_chore_name=""
|
||||||
|
|
||||||
rt_script_dir=$(realpath "$(dirname "$0")")
|
rt_script_dir=$(realpath "$(dirname "$0")")
|
||||||
rt_has_mode_changed=0
|
rt_has_mode_changed=0
|
||||||
|
rt_current_mode="unset"
|
||||||
|
|
||||||
reve_folder="$HOME/.config/reve"
|
reve_folder="$HOME/.config/reve"
|
||||||
reve_desktop_mode="$reve_folder/desktop_mode"
|
reve_desktop_mode="$reve_folder/desktop_mode"
|
||||||
reve_time_day="$reve_folder/time_day"
|
|
||||||
reve_time_night="$reve_folder/time_night"
|
|
||||||
|
|
||||||
reve_chores_mode="$rt_script_dir/chores/mode"
|
reve_chores_mode="$rt_script_dir/chores/mode"
|
||||||
|
|
||||||
@ -54,10 +56,6 @@ util_help () {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
util_mkdirs () {
|
|
||||||
mkdir -p "$reve_folder"
|
|
||||||
}
|
|
||||||
|
|
||||||
f_shell_completion () {
|
f_shell_completion () {
|
||||||
if [ "$in_shell_comp" == "fish" ]; then
|
if [ "$in_shell_comp" == "fish" ]; then
|
||||||
cp "$rt_script_dir/completions/reve.fish" "$HOME/.config/fish/completions/reve.fish"
|
cp "$rt_script_dir/completions/reve.fish" "$HOME/.config/fish/completions/reve.fish"
|
||||||
@ -71,10 +69,6 @@ f_shell_completion () {
|
|||||||
if ! grep -q "_reve_completions" "$HOME/.bash_completion"; then
|
if ! grep -q "_reve_completions" "$HOME/.bash_completion"; then
|
||||||
echo "$_reve_completions" >> "$HOME/.bash_completion"
|
echo "$_reve_completions" >> "$HOME/.bash_completion"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$BASH_SOURCE" ]; then
|
|
||||||
source "$HOME/.bash_completion"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,44 +78,34 @@ set_desktop_mode () {
|
|||||||
return 1 # since mode has changed
|
return 1 # since mode has changed
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local current_mode="unset"
|
local previous_mode num_day num_night current_time
|
||||||
local previous_mode day_start night_start num_day num_night current_time
|
previous_mode=$( util_read_config base.desktop_mode )
|
||||||
previous_mode=$( util_readf "$reve_desktop_mode" )
|
num_day=$( awk -F: '{print $1 * 60 + $2}' <<< "$( util_read_config base.time_day )" )
|
||||||
day_start=$( util_readf "$reve_time_day" )
|
num_night=$( awk -F: '{print $1 * 60 + $2}' <<< "$( util_read_config base.time_night )" )
|
||||||
night_start=$( util_readf "$reve_time_night" )
|
|
||||||
num_day=$( awk -F: '{print $1 * 60 + $2}' <<< "$day_start" )
|
|
||||||
num_night=$( awk -F: '{print $1 * 60 + $2}' <<< "$night_start" )
|
|
||||||
current_time=$( awk -F: '{print $1 * 60 + $2}' <<< "$(date +%H:%M)" )
|
current_time=$( awk -F: '{print $1 * 60 + $2}' <<< "$(date +%H:%M)" )
|
||||||
|
|
||||||
if ((num_night > current_time && current_time >= num_day)); then
|
if ((num_night > current_time && current_time >= num_day)); then
|
||||||
current_mode="light"
|
rt_current_mode="light"
|
||||||
else
|
else
|
||||||
current_mode="dark"
|
rt_current_mode="dark"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[reve] [I] Setting the mode: $current_mode"
|
echo "[reve] [I] Setting the mode: $rt_current_mode"
|
||||||
echo "$current_mode" > "$reve_desktop_mode"
|
echo "$rt_current_mode" > "$reve_desktop_mode"
|
||||||
|
|
||||||
if [ "$current_mode" == "$previous_mode" ]; then
|
if [ "$rt_current_mode" == "$previous_mode" ]; then
|
||||||
return 0 # since mode did not change
|
return 0 # since mode did not change
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare () {
|
|
||||||
util_mkdirs
|
|
||||||
set_desktop_mode
|
|
||||||
rt_has_mode_changed="$?"
|
|
||||||
echo $rt_has_mode_changed
|
|
||||||
}
|
|
||||||
|
|
||||||
# Called when the mode (the default state, is either dark or light) changes
|
# Called when the mode (the default state, is either dark or light) changes
|
||||||
chores_mode () {
|
chores_mode () {
|
||||||
for file in "$reve_chores_mode"/*; do
|
for file in "$reve_chores_mode"/*; do
|
||||||
if [ -x "$file" ]; then
|
if [ -x "$file" ]; then
|
||||||
echo "[reve] [I] Running chore: $( basename "$file" )"
|
echo "[reve] [I] Running chore: $( basename "$file" )"
|
||||||
bash "$file"
|
util_run_chore "$file" $rt_current_mode
|
||||||
else
|
else
|
||||||
echo "[reve] [E] chores_mode: $file is not executable"
|
echo "[reve] [E] chores_mode: $file is not executable"
|
||||||
fi
|
fi
|
||||||
@ -129,7 +113,9 @@ chores_mode () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
util_handle_pos () {
|
util_handle_pos () {
|
||||||
local forced_mode
|
# args: $@ -- handles positionals
|
||||||
|
# returns: 'light' or 'dark' depending on positionals or $rt_current_mode
|
||||||
|
local forced_mode=$rt_current_mode
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
if [[ "$arg" == "-d" || "$arg" == "--dark" ]]; then
|
if [[ "$arg" == "-d" || "$arg" == "--dark" ]]; then
|
||||||
forced_mode="dark"
|
forced_mode="dark"
|
||||||
@ -137,10 +123,7 @@ util_handle_pos () {
|
|||||||
forced_mode="light"
|
forced_mode="light"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
echo $forced_mode
|
||||||
if [[ $( util_read_config base.desktop_mode ) != "$forced_mode" ]]; then
|
|
||||||
util_write_config "$forced_mode"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub_config () {
|
sub_config () {
|
||||||
@ -158,18 +141,24 @@ sub_config () {
|
|||||||
util_help config
|
util_help config
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "[reve] [E] in subcommand config: '$1' is not a valid command"
|
echo "reve: in subcommand config: '$1' is not a valid command"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
main () {
|
main () {
|
||||||
if (( rt_has_mode_changed == 1 )) || [[ "$in_reason" == "chores_mode" ]]; then
|
mkdir -p "$reve_folder"
|
||||||
chores_mode
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$in_chore_name" != "" ]]; then
|
if [[ "$in_chore_name" != "" ]]; then
|
||||||
util_run_chore "$in_chore_name"
|
forced_mode=$(util_handle_pos "$@")
|
||||||
|
util_run_chore "$in_chore_name" $forced_mode
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
set_desktop_mode
|
||||||
|
rt_has_mode_changed="$?"
|
||||||
|
if (( rt_has_mode_changed == 1 )) || [[ "$in_reason" == "chores_mode" ]]; then
|
||||||
|
chores_mode
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,10 +191,7 @@ case "$1" in
|
|||||||
in_reason="$2"
|
in_reason="$2"
|
||||||
;;
|
;;
|
||||||
chore)
|
chore)
|
||||||
util_handle_pos "$@"
|
in_chore_name="$2"
|
||||||
util_run_chore "$2"
|
|
||||||
util_toggle_dm
|
|
||||||
exit 0
|
|
||||||
;;
|
;;
|
||||||
poll)
|
poll)
|
||||||
;;
|
;;
|
||||||
@ -214,10 +200,9 @@ case "$1" in
|
|||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Invalid command or subcommand: $1"
|
echo "reve: invalid command or subcommand: $1"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
prepare "$@"
|
main "$@"
|
||||||
main
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user