formatting <<< moving 2 spaces to left <<<

This commit is contained in:
yigid balaban 2024-10-02 17:46:46 +03:00
parent 913cd0d65e
commit b6bac4bbdc
Signed by: fyb
GPG Key ID: CF1BBD1336C0A3D6

65
reve.sh
View File

@ -22,13 +22,13 @@ reve_chores_mode="$rt_script_dir/chores/mode"
# bring reve utility functions to the context # bring reve utility functions to the context
# shellcheck source=_reve.sh # shellcheck source=_reve.sh
source "$rt_script_dir/_reve" >&/dev/null source "$rt_script_dir/_reve" >&/dev/null
(( $? == 1 )) && source "$rt_script_dir/_reve.sh" # looks like we're in dev environment (($? == 1)) && source "$rt_script_dir/_reve.sh" # looks like we're in dev environment
util_help () { util_help() {
local command="$1" local command="$1"
case $command in case $command in
reve|'') reve | '')
echo "=> Usage: reve [command] OR reve [subcommand] [command]" echo "=> Usage: reve [command] OR reve [subcommand] [command]"
echo "== Commands ==" echo "== Commands =="
echo "mode {desktop_mode} sets desktop mode, accepts 'dark' or 'light'" echo "mode {desktop_mode} sets desktop mode, accepts 'dark' or 'light'"
@ -56,33 +56,33 @@ util_help () {
esac esac
} }
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"
elif [ "$in_shell_comp" == "bash" ]; then elif [ "$in_shell_comp" == "bash" ]; then
_reve_completions=$( util_readf "$rt_script_dir/completions/reve.bash" ) _reve_completions=$(util_readf "$rt_script_dir/completions/reve.bash")
if [ ! -f "$HOME/.bash_completion" ]; then if [ ! -f "$HOME/.bash_completion" ]; then
touch "$HOME/.bash_completion" touch "$HOME/.bash_completion"
fi fi
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
fi fi
} }
set_desktop_mode () { set_desktop_mode() {
if [[ -n "$in_desktop_mode" ]]; then if [[ -n "$in_desktop_mode" ]]; then
echo "$in_desktop_mode" > "$reve_desktop_mode" echo "$in_desktop_mode" >"$reve_desktop_mode"
return 1 # since mode has changed return 1 # since mode has changed
fi fi
local previous_mode num_day num_night current_time local previous_mode num_day num_night current_time
previous_mode=$( util_read_config base.desktop_mode ) previous_mode=$(util_read_config base.desktop_mode)
num_day=$( awk -F: '{print $1 * 60 + $2}' <<< "$( util_read_config base.time_day )" ) num_day=$(awk -F: '{print $1 * 60 + $2}' <<<"$(util_read_config base.time_day)")
num_night=$( awk -F: '{print $1 * 60 + $2}' <<< "$( util_read_config base.time_night )" ) num_night=$(awk -F: '{print $1 * 60 + $2}' <<<"$(util_read_config base.time_night)")
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
rt_current_mode="light" rt_current_mode="light"
@ -91,7 +91,7 @@ set_desktop_mode () {
fi fi
echo "[reve] [I] Setting the mode: $rt_current_mode" echo "[reve] [I] Setting the mode: $rt_current_mode"
echo "$rt_current_mode" > "$reve_desktop_mode" echo "$rt_current_mode" >"$reve_desktop_mode"
if [ "$rt_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
@ -101,10 +101,10 @@ set_desktop_mode () {
} }
# 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")"
util_run_chore "$file" $rt_current_mode 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"
@ -112,7 +112,7 @@ chores_mode () {
done done
} }
util_handle_pos () { util_handle_pos() {
# args: $@ -- handles positionals # args: $@ -- handles positionals
# returns: 'light' or 'dark' depending on positionals or $rt_current_mode # returns: 'light' or 'dark' depending on positionals or $rt_current_mode
local forced_mode=$rt_current_mode local forced_mode=$rt_current_mode
@ -126,7 +126,7 @@ util_handle_pos () {
echo $forced_mode echo $forced_mode
} }
sub_config () { sub_config() {
case "$1" in case "$1" in
get) get)
util_read_config "$2" util_read_config "$2"
@ -134,7 +134,7 @@ sub_config () {
set) set)
util_write_config "$2" "$3" util_write_config "$2" "$3"
;; ;;
rm|delete) rm | delete)
util_delete_config "$2" util_delete_config "$2"
;; ;;
"") "")
@ -146,7 +146,7 @@ sub_config () {
esac esac
} }
main () { main() {
mkdir -p "$reve_folder" mkdir -p "$reve_folder"
if [[ "$in_chore_name" != "" ]]; then if [[ "$in_chore_name" != "" ]]; then
@ -157,49 +157,48 @@ main () {
set_desktop_mode set_desktop_mode
rt_has_mode_changed="$?" rt_has_mode_changed="$?"
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
fi fi
} }
case "$1" in case "$1" in
config) config)
sub_config "$2" "$3" "$4" sub_config "$2" "$3" "$4"
exit 0 exit 0
;; ;;
update) update)
sub_update sub_update
exit 0 exit 0
;; ;;
help) help)
util_help "$2" util_help "$2"
exit 0 exit 0
;; ;;
where) where)
dirname "$( which reve )" dirname "$(which reve)"
exit 0 exit 0
;; ;;
shell-completion) shell-completion)
in_shell_comp="$2" in_shell_comp="$2"
f_shell_completion f_shell_completion
exit 0 exit 0
;; ;;
mode) mode)
in_desktop_mode="$2" in_desktop_mode="$2"
;; ;;
reason) reason)
in_reason="$2" in_reason="$2"
;; ;;
chore) chore)
in_chore_name="$2" in_chore_name="$2"
;; ;;
poll) poll) ;;
;; "")
"")
util_help "$2" util_help "$2"
exit 0 exit 0
;; ;;
*) *)
echo "reve: invalid command or subcommand: $1" echo "reve: invalid command or subcommand: $1"
exit 1 exit 1
;; ;;