Compare commits
13 Commits
913cd0d65e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
85509d556c
|
|||
|
9fd1a31bdb
|
|||
|
a6bc546570
|
|||
|
7e300fc04e
|
|||
|
0602eb1bf7
|
|||
|
02fcdf794b
|
|||
|
245dc99887
|
|||
|
dd663f47a0
|
|||
|
49c80b4b3d
|
|||
|
8f5225cb23
|
|||
|
e4917fddec
|
|||
|
967f3c50e4
|
|||
|
b6bac4bbdc
|
27
_reve.sh
27
_reve.sh
@@ -7,16 +7,13 @@
|
|||||||
reve_installation="$HOME/.local/bin/reve"
|
reve_installation="$HOME/.local/bin/reve"
|
||||||
reve_config="$HOME/.config/reve"
|
reve_config="$HOME/.config/reve"
|
||||||
|
|
||||||
util_readf() {
|
_current_dir=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
|
||||||
local filename=$1
|
# shellcheck source=_reve_states.sh
|
||||||
|
source "$_current_dir/_reve_states" >&/dev/null
|
||||||
if [[ -f "$filename" ]]; then
|
(($? == 1)) && source "$_current_dir/_reve_states.sh"
|
||||||
cat "$filename"
|
# shellcheck source=_reve_utils.sh
|
||||||
else
|
source "$_current_dir/_reve_utils" >&/dev/null
|
||||||
error E "util_readf" "File not found: $filename"
|
(($? == 1)) && source "$_current_dir/_reve_utils.sh"
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
util_where_config() {
|
util_where_config() {
|
||||||
local config_key=$1
|
local config_key=$1
|
||||||
@@ -69,7 +66,7 @@ util_run_utility() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reload() {
|
reload() {
|
||||||
util_run_chore "$1"
|
util_run_chore "$1" "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
reload_util() {
|
reload_util() {
|
||||||
@@ -83,11 +80,3 @@ util_toggle_dm() {
|
|||||||
util_write_config base.desktop_mode dark
|
util_write_config base.desktop_mode dark
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
error() {
|
|
||||||
local level=$1 location=$2 cause=$3
|
|
||||||
message="[reve] [$level] [$location] $cause"
|
|
||||||
echo "$message"
|
|
||||||
now=$(date -Iminutes)
|
|
||||||
echo "${now::-6} $message" >>"$reve_installation/reve.log"
|
|
||||||
}
|
|
||||||
|
|||||||
99
_reve_states.sh
Normal file
99
_reve_states.sh
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# reve desktop environment framework
|
||||||
|
# Yigid BALABAN <fyb@fybx.dev> 2024
|
||||||
|
|
||||||
|
# reve internal: _reve_states
|
||||||
|
# defines state management API
|
||||||
|
|
||||||
|
_current_dir=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
|
||||||
|
# shellcheck source=_reve_utils.sh
|
||||||
|
source "$_current_dir/_reve_utils" >&/dev/null
|
||||||
|
(($? == 1)) && source "$_current_dir/_reve_utils.sh"
|
||||||
|
|
||||||
|
REVE_STATE_REPO="$HOME/.local/bin/reve/states"
|
||||||
|
|
||||||
|
__util_pathto_state() {
|
||||||
|
# args: $1 -- state key
|
||||||
|
# args: $2 -- state type
|
||||||
|
local key=$1 type=$2
|
||||||
|
|
||||||
|
pre_removed_key=${key/#base./}
|
||||||
|
state_path="$(echo "$pre_removed_key" | sed 's/\./\//g')$type"
|
||||||
|
echo "$state_path"
|
||||||
|
}
|
||||||
|
|
||||||
|
__util_find_state() {
|
||||||
|
# args: $1 -- state key
|
||||||
|
# returns: 1 if state key not in map
|
||||||
|
# 2 if map is corrupted
|
||||||
|
local key=$1
|
||||||
|
|
||||||
|
type=$(awk -F'=' -v key="$key" '$1 == key {print $2}' "$REVE_STATE_REPO/map")
|
||||||
|
case "$type" in
|
||||||
|
prs | persistent) type="" ;;
|
||||||
|
tmp | temporary) type=".tmp" ;;
|
||||||
|
"")
|
||||||
|
error E states "state referenced by key '$key' doesn't exist"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
error E states "state map '$REVE_STATE_REPO/map' is corrupted"
|
||||||
|
return 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
__util_pathto_state "$1" "$type"
|
||||||
|
}
|
||||||
|
|
||||||
|
util_create_state() {
|
||||||
|
local type=$1 key=$2 value=$3
|
||||||
|
|
||||||
|
if [ "$type" != "tmp" ] && [ "$type" != "prs" ]; then
|
||||||
|
error E util_create_state "can't create state with type '$type'"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! __util_find_state "$key"; then
|
||||||
|
echo "$value" >"$(__util_pathto_state "$key" "$type")"
|
||||||
|
echo "$key=$value" >"$REVE_STATE_REPO/map"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
util_write_state() {
|
||||||
|
local key=$1 value=$2
|
||||||
|
|
||||||
|
_path=$(__util_find_state "$key")
|
||||||
|
if $? -eq 0; then
|
||||||
|
echo "$value" >"$_path"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
util_read_state() {
|
||||||
|
local key=$1
|
||||||
|
|
||||||
|
_path=$(__util_find_state "$key")
|
||||||
|
if $? -eq 0; then
|
||||||
|
cat "$_path"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
util_delete_state() {
|
||||||
|
local key=$1
|
||||||
|
|
||||||
|
_path=$(__util_find_state "$key")
|
||||||
|
if $? -eq 0; then
|
||||||
|
rm "$_path"
|
||||||
|
awk -F '=' -v key="$key" '$1 != key' "$REVE_STATE_REPO/map" >"$REVE_STATE_REPO/map.tmp"
|
||||||
|
mv "$REVE_STATE_REPO/map.tmp" "$REVE_STATE_REPO/map"
|
||||||
|
|
||||||
|
_dir=$(dirname "$_path")
|
||||||
|
[ -z "$(ls -A "$_dir")" ] && rm -r "$_dir"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
util_deleteall_temp() {
|
||||||
|
awk -F'=' '$2 == "tmp" { print $1 }' data.txt | while read -r key; do
|
||||||
|
util_delete_state "$key"
|
||||||
|
done
|
||||||
|
}
|
||||||
29
_reve_utils.sh
Normal file
29
_reve_utils.sh
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# reve desktop environment framework
|
||||||
|
# Yigid BALABAN <fyb@fybx.dev> 2024
|
||||||
|
|
||||||
|
# reve internal: _reve_utils
|
||||||
|
# defines utility functions
|
||||||
|
|
||||||
|
# VERY CRITICAL: change this if install.sh is updated
|
||||||
|
reve_installation="$HOME/.local/bin/reve"
|
||||||
|
|
||||||
|
util_readf() {
|
||||||
|
local filename=$1
|
||||||
|
|
||||||
|
if [[ -f "$filename" ]]; then
|
||||||
|
cat "$filename"
|
||||||
|
else
|
||||||
|
error E "util_readf" "File not found: $filename"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
local level=$1 location=$2 cause=$3
|
||||||
|
message="[reve] [$level] [$location] $cause"
|
||||||
|
echo "$message"
|
||||||
|
now=$(date -Iminutes)
|
||||||
|
echo "${now::-6} $message" >>"$reve_installation/reve.log"
|
||||||
|
}
|
||||||
27
chores/misc/asus_kbd_light.sh
Executable file
27
chores/misc/asus_kbd_light.sh
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# reve desktop environment framework
|
||||||
|
# Yigid BALABAN <fyb@fybx.dev> 2024
|
||||||
|
|
||||||
|
# chore script
|
||||||
|
# type misc
|
||||||
|
# name asus_kbd_light.sh
|
||||||
|
# desc ...
|
||||||
|
# vars ...
|
||||||
|
# reload ...
|
||||||
|
|
||||||
|
reve_folder="$HOME/.config/reve"
|
||||||
|
reve_desktop_mode="$reve_folder/desktop_mode"
|
||||||
|
|
||||||
|
source "$( reve -w )/_reve"
|
||||||
|
|
||||||
|
current_mode=$( util_readf "$reve_desktop_mode" )
|
||||||
|
|
||||||
|
if [ "$current_mode" == "light" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
hex_dominant_color=$( magick "$reve_folder/chore/bg_dark" -resize 1x1\! -format "%[hex:p{0,0}]" info: )
|
||||||
|
|
||||||
|
asusctl led-mode static -c "$hex_dominant_color"
|
||||||
|
asusctl --kbd-bright med
|
||||||
20
chores/mode/display_brightness.sh
Executable file
20
chores/mode/display_brightness.sh
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# reve desktop environment framework
|
||||||
|
# Yigid BALABAN <fyb@fybx.dev> 2024
|
||||||
|
|
||||||
|
# chore script
|
||||||
|
# type mode
|
||||||
|
# name display_brightness.sh
|
||||||
|
# desc sets display brightness depending on the desktop_mode
|
||||||
|
# vars day_level, night_level
|
||||||
|
# reload none
|
||||||
|
|
||||||
|
# shellcheck source=../../_reve.sh
|
||||||
|
source "$(reve where)/_reve"
|
||||||
|
|
||||||
|
if [ "$RV_CURRENT_MODE" == "dark" ]; then
|
||||||
|
brightnessctl set "$(util_read_config display.night_level)"
|
||||||
|
else
|
||||||
|
brightnessctl set "$(util_read_config display.day_level)"
|
||||||
|
fi
|
||||||
@@ -12,5 +12,16 @@
|
|||||||
# shellcheck source=../../_reve.sh
|
# shellcheck source=../../_reve.sh
|
||||||
source "$(reve where)/_reve"
|
source "$(reve where)/_reve"
|
||||||
|
|
||||||
gsettings set org.gnome.desktop.interface gtk-theme "$(util_read_config chore.gtk_"$RV_CURRENT_MODE"_theme)"
|
key="org.gnome.desktop.interface"
|
||||||
gsettings set org.gnome.desktop.interface color-scheme prefer-"$RV_CURRENT_MODE"
|
target_theme="$(util_read_config chore.gtk_"$RV_CURRENT_MODE"_theme)"
|
||||||
|
target_scheme="prefer-$RV_CURRENT_MODE"
|
||||||
|
|
||||||
|
if ! gsettings set "$key" gtk-theme "$target_theme" ||
|
||||||
|
[ "$(gsettings get "$key" gtk-theme | tr -d \')" != "$target_theme" ]; then
|
||||||
|
error E mode/gtk-theme "Could not set gtk-theme to: $target_theme"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! gsettings set "$key" color-scheme "$target_scheme" ||
|
||||||
|
[ "$(gsettings get "$key" color-scheme | tr -d \')" != "$target_scheme" ]; then
|
||||||
|
error E mode/gtk-theme "Could not set color-scheme to: $target_scheme"
|
||||||
|
fi
|
||||||
|
|||||||
35
chores/mode/hyprpaper_single.sh
Normal file
35
chores/mode/hyprpaper_single.sh
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# reve desktop environment framework
|
||||||
|
# Yigid BALABAN <fyb@fybx.dev> 2024
|
||||||
|
|
||||||
|
# chore script
|
||||||
|
# type mode
|
||||||
|
# name hyprpaper_single.sh
|
||||||
|
# desc changes the background depending on the desktop_mode
|
||||||
|
# vars bg_dark, bg_light
|
||||||
|
# reload none
|
||||||
|
|
||||||
|
if ! command -v hyprpaper &>/dev/null; then
|
||||||
|
echo "hyprpaper is not installed. Please install it and try again."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# shellcheck source=../../_reve.sh
|
||||||
|
source "$(reve where)/_reve"
|
||||||
|
|
||||||
|
bg="$(util_read_config chore."bg_$RV_CURRENT_MODE")"
|
||||||
|
current_bg="$(util_where_config chore.current_bg)"
|
||||||
|
|
||||||
|
# Only change if different from current
|
||||||
|
if [ "$bg" != "$(readlink -f "$current_bg")" ]; then
|
||||||
|
hyprctl hyprpaper preload "$bg"
|
||||||
|
hyprctl hyprpaper wallpaper ",${bg}"
|
||||||
|
hyprctl hyprpaper unload unused
|
||||||
|
cp "$bg" "$current_bg"
|
||||||
|
|
||||||
|
notify-send --urgency=low --expire-time=1450 --icon="$bg" \
|
||||||
|
--app-name="reve: hyprpaper_single" \
|
||||||
|
"Wallpaper changed" \
|
||||||
|
"Wallpaper changed and saved on $RV_CURRENT_MODE mode."
|
||||||
|
fi
|
||||||
@@ -17,4 +17,4 @@ if ! command -v kitty &>/dev/null; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
kitten themes --reload-in=all "$(util_read_config chore.kitty."$RV_CURRENT_THEME")"
|
kitten themes --reload-in=all "$(util_read_config chore.kitty."$RV_CURRENT_MODE")"
|
||||||
|
|||||||
20
chores/mode/nvim_theme.sh
Executable file
20
chores/mode/nvim_theme.sh
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# reve desktop environment framework
|
||||||
|
# Yigid BALABAN <fyb@fybx.dev> 2024
|
||||||
|
|
||||||
|
# chore script
|
||||||
|
# type mode
|
||||||
|
# name nvim_theme.sh
|
||||||
|
# desc sends a signal to nvim to fetch desktop_mode
|
||||||
|
# vars none
|
||||||
|
# reload none
|
||||||
|
|
||||||
|
handle_usr1() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
trap handle_usr1 USR1
|
||||||
|
|
||||||
|
if pids=$(pgrep -f 'nvim'); then
|
||||||
|
echo "$pids" | xargs kill -USR1
|
||||||
|
fi
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# reve desktop environment framework
|
# reve desktop environment framework
|
||||||
# Yigid BALABAN <fyb@fybx.dev> 2024
|
# Yigid BALABAN <fyb@fybx.dev> 2024
|
||||||
@@ -23,7 +23,8 @@ ltypes=${#types[@]}
|
|||||||
rindex=$((RANDOM % ltypes))
|
rindex=$((RANDOM % ltypes))
|
||||||
rtype=${types[rindex]}
|
rtype=${types[rindex]}
|
||||||
|
|
||||||
bg="$(util_where_config chore."bg_$RV_CURRENT_MODE")"
|
bg="$(util_read_config chore."bg_$RV_CURRENT_MODE")"
|
||||||
swww img --transition-type "$rtype" --transition-pos 1,1 --transition-step 90 "$bg"
|
swww img --transition-type "$rtype" --transition-pos 1,1 --transition-step 90 "$bg"
|
||||||
notify-send --urgency=low --expire-time=1450 --icon="$bg" --app-name="reve: swww_single" "Wallpaper changed" "Wallpaper changed and saved on light mode."
|
notify-send --urgency=low --expire-time=1450 --icon="$bg" --app-name="reve: swww_single" "Wallpaper changed" "Wallpaper changed and saved on $RV_CURRENT_MODE mode."
|
||||||
|
cp "$bg" "$(util_where_config chore.current_bg)"
|
||||||
reload misc/asus_kbd_light.sh
|
reload misc/asus_kbd_light.sh
|
||||||
|
|||||||
22
chores/mode/swww_slideshow.sh
Executable file
22
chores/mode/swww_slideshow.sh
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# reve desktop environment framework
|
||||||
|
# Yigid BALABAN <fyb@fybx.dev> 2024
|
||||||
|
|
||||||
|
# chore script
|
||||||
|
# type mode
|
||||||
|
# name swww-based wallpaper slideshow
|
||||||
|
# desc reruns utility/swww_slideshow when mode changes
|
||||||
|
# vars swwwss.dark, swwwss.light, swwwss.folder
|
||||||
|
# reload no
|
||||||
|
|
||||||
|
# shellcheck source=../../_reve.sh
|
||||||
|
source "$(reve where)/_reve"
|
||||||
|
|
||||||
|
desktop_mode=$(util_read_config base.desktop_mode)
|
||||||
|
|
||||||
|
if [ "$desktop_mode" == "dark" ]; then
|
||||||
|
util_write_config swwwss.folder "$(util_read_config swwwss.dark)"
|
||||||
|
else
|
||||||
|
util_write_config swwwss.folder "$(util_read_config swwwss.light)"
|
||||||
|
fi
|
||||||
0
chores/power/laptop_disp_rr.sh
Executable file
0
chores/power/laptop_disp_rr.sh
Executable file
26
docs/about_states.md
Normal file
26
docs/about_states.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# reve docs
|
||||||
|
|
||||||
|
"about states", revision 1
|
||||||
|
yigid balaban \<fyb@fybx.dev\>
|
||||||
|
|
||||||
|
## about states
|
||||||
|
|
||||||
|
different from configuration files, some information is temporary, and "local" to current runtime. some utilities, for example, may need a way to store and access variables. for that reason reve exposes 4 functions to work with states that can be temporary or permanent.
|
||||||
|
|
||||||
|
for this reason, states can be created/updated, deleted or read using reve.
|
||||||
|
|
||||||
|
### reve's API for states
|
||||||
|
|
||||||
|
Functions for working with states are defined in `_reve.sh`:
|
||||||
|
|
||||||
|
1. `util_create_state {type} {key} [value]`: Creates the state file. `{type}` can be `tmp` for temporary or `prs` for persistent.
|
||||||
|
1. `util_read_state {key}`: Returns the value read from file addressed by key. Will return `1` if an error occurs.
|
||||||
|
2. `util_write_state {key} {value}`: Writes the value to file addressed by key. Will **overwrite** without warning.
|
||||||
|
3. `util_delete_state {key}`: Deletes the file addressed by key. Will delete the containing folder, if the folder is empty.
|
||||||
|
|
||||||
|
### underlying implementation
|
||||||
|
|
||||||
|
- the `key`s are dot-delimited folders, subfolders and files. The last element of the key is assumed to be the file name.
|
||||||
|
- trying to read, write or delete a file that is not created will return an error.
|
||||||
|
- as a result of the rule above, writing a new state is not possible, you have to create it with an explicit type first.
|
||||||
|
- temporary states will be cleaned when the appropriate call is made (`reve state clean`)
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
#!/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
|
||||||
|
|
||||||
# chore script
|
# chore script
|
||||||
# type mode
|
# type mode
|
||||||
# name chore_script.sh
|
# name chore_script.sh
|
||||||
# desc ...
|
# desc ...
|
||||||
# vars ...
|
# vars ...
|
||||||
|
# reload ...
|
||||||
|
|
||||||
reve_folder="$HOME/.config/reve"
|
# shellcheck source=../_reve.sh
|
||||||
reve_desktop_mode="$reve_folder/desktop_mode"
|
source "$(reve where)/_reve"
|
||||||
|
|
||||||
source "$( reve -w )/_reve"
|
echo "Hello, world! Current mode is $RV_CURRENT_MODE."
|
||||||
|
|
||||||
current_mode=$( util_readf "$reve_desktop_mode" )
|
reload mode/gtk_theme
|
||||||
echo "Hello, world! Current mode is $current_mode."
|
|
||||||
|
|||||||
50
install.sh
50
install.sh
@@ -4,48 +4,52 @@
|
|||||||
# Yigid BALABAN <fyb@fybx.dev> 2024
|
# Yigid BALABAN <fyb@fybx.dev> 2024
|
||||||
|
|
||||||
rt_script_dir=$(realpath "$(dirname "$0")")
|
rt_script_dir=$(realpath "$(dirname "$0")")
|
||||||
cd "$rt_script_dir" || exit
|
cd "$rt_script_dir" || exit
|
||||||
|
|
||||||
reve_installation_target="$HOME/.local/bin/reve"
|
reve_installation_target="$HOME/.local/bin/reve"
|
||||||
|
|
||||||
echo "[1/5] Creating reve installation folder"
|
echo "[1/5] Creating reve installation folder"
|
||||||
mkdir -p "$reve_installation_target"
|
mkdir -p "$reve_installation_target"
|
||||||
|
|
||||||
echo "[2/5] Copying: reve.sh and _reve.sh"
|
echo "[2/5] Copying: reve.sh and other internal tools"
|
||||||
cp reve.sh "$reve_installation_target/reve"
|
cp reve.sh "$reve_installation_target/reve"
|
||||||
cp _reve.sh "$reve_installation_target/_reve"
|
cp _reve.sh "$reve_installation_target/_reve"
|
||||||
|
cp _reve_utils.sh "$reve_installation_target/_reve_utils"
|
||||||
|
cp _reve_states.sh "$reve_installation_target/_reve_states"
|
||||||
chmod +x "$reve_installation_target/reve"
|
chmod +x "$reve_installation_target/reve"
|
||||||
chmod -x "$reve_installation_target/_reve"
|
chmod -x "$reve_installation_target/_reve"
|
||||||
|
chmod -x "$reve_installation_target/_reve_utils"
|
||||||
|
chmod -x "$reve_installation_target/_reve_states"
|
||||||
|
|
||||||
echo "[3/5] Adding reve to path"
|
echo "[3/5] Adding reve to path"
|
||||||
if grep -q "/bin/bash" /etc/shells; then
|
if grep -q "/bin/bash" /etc/shells; then
|
||||||
echo "==> bash detected."
|
echo "==> bash detected."
|
||||||
if ! grep -q "$reve_installation_target" ~/.bashrc; then
|
if ! grep -q "$reve_installation_target" ~/.bashrc; then
|
||||||
echo "export PATH=\"\$PATH:$reve_installation_target\"" >> ~/.bashrc
|
echo "export PATH=\"\$PATH:$reve_installation_target\"" >>~/.bashrc
|
||||||
echo "Added $reve_installation_target to bash PATH."
|
echo "Added $reve_installation_target to bash PATH."
|
||||||
else
|
else
|
||||||
echo "$reve_installation_target is already in bash PATH."
|
echo "$reve_installation_target is already in bash PATH."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if grep -q "/bin/zsh" /etc/shells; then
|
if grep -q "/bin/zsh" /etc/shells; then
|
||||||
echo "==> zsh detected."
|
echo "==> zsh detected."
|
||||||
if ! grep -q "$reve_installation_target" ~/.zshrc; then
|
if ! grep -q "$reve_installation_target" ~/.zshrc; then
|
||||||
echo "export PATH=\"\$PATH:$reve_installation_target\"" >> ~/.zshrc
|
echo "export PATH=\"\$PATH:$reve_installation_target\"" >>~/.zshrc
|
||||||
echo "Added $reve_installation_target to zsh PATH."
|
echo "Added $reve_installation_target to zsh PATH."
|
||||||
else
|
else
|
||||||
echo "$reve_installation_target is already in zsh PATH."
|
echo "$reve_installation_target is already in zsh PATH."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if grep -q "/bin/fish" /etc/shells; then
|
if grep -q "/bin/fish" /etc/shells; then
|
||||||
echo "==> fish detected."
|
echo "==> fish detected."
|
||||||
if ! fish -c "echo $PATH | grep -q $reve_installation_target"; then
|
if ! fish -c "echo $PATH | grep -q $reve_installation_target"; then
|
||||||
fish -c "fish_add_path $reve_installation_target"
|
fish -c "fish_add_path $reve_installation_target"
|
||||||
echo "Added $reve_installation_target to fish PATH."
|
echo "Added $reve_installation_target to fish PATH."
|
||||||
else
|
else
|
||||||
echo "$reve_installation_target is already in fish PATH."
|
echo "$reve_installation_target is already in fish PATH."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[4/5] Creating chores/mode folder"
|
echo "[4/5] Creating chores/mode folder"
|
||||||
|
|||||||
408
reve.sh
408
reve.sh
@@ -10,7 +10,7 @@ in_desktop_mode=""
|
|||||||
in_reason=""
|
in_reason=""
|
||||||
in_chore_name=""
|
in_chore_name=""
|
||||||
|
|
||||||
rt_script_dir=$(realpath "$(dirname "$0")")
|
rt_script_dir=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
|
||||||
rt_has_mode_changed=0
|
rt_has_mode_changed=0
|
||||||
rt_current_mode="unset"
|
rt_current_mode="unset"
|
||||||
|
|
||||||
@@ -22,187 +22,291 @@ 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'"
|
||||||
echo "reason {reason} run reve with reason, accepts 'network' or 'time'"
|
echo "reason {reason} run reve with reason, accepts 'network' or 'time'"
|
||||||
echo "chore {chore_name} run a single chore, accepts chore name"
|
echo "chore {chore_name} run a single chore, accepts chore name"
|
||||||
echo "where returns where reve's installed"
|
echo "where returns where reve's installed"
|
||||||
echo "poll runs reve to update desktop_mode & power_mode, and do chores"
|
echo "poll runs reve to update desktop_mode & power_mode, and do chores"
|
||||||
echo "help [subcommand] shows help message"
|
echo "help [subcommand] shows help message"
|
||||||
echo "== Subcommands =="
|
echo "== Subcommands =="
|
||||||
echo "1. config gets/sets configuration values"
|
echo "1. config gets/sets configuration values"
|
||||||
echo "2. update updates chores"
|
echo "2. update updates chores"
|
||||||
;;
|
echo "3. chores manages installed chores"
|
||||||
config)
|
;;
|
||||||
echo "=> Usage"
|
config)
|
||||||
echo "1. reve config get {config_key} get the value stored in file"
|
echo "=> Usage"
|
||||||
echo "2. reve config set {config_key} {value} set the value of file"
|
echo "1. reve config get {config_key} get the value stored in file"
|
||||||
echo "3. reve config rm {config_key} delete the config 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"
|
update)
|
||||||
echo "== Details =="
|
echo "=> Usage: reve update [chore names...] updates chores from upstream"
|
||||||
echo "Updates all chores present on your configuration if nothing is given. The"
|
echo "== Details =="
|
||||||
echo "chore names must be space delimited."
|
echo "Updates all chores present on your installation if nothing is given."
|
||||||
;;
|
echo "The chore names must be space delimited."
|
||||||
esac
|
;;
|
||||||
|
chores)
|
||||||
|
echo "=> Usage"
|
||||||
|
echo "1. reve chores list lists all installed chores"
|
||||||
|
echo "2. reve chores add {chore_name} adds chore_name from .reve_repo"
|
||||||
|
echo "3. reve chores rm {chore_name} removes chore_name from installation"
|
||||||
|
echo "4. reve chores more lists chores available for installation"
|
||||||
|
echo "== Details =="
|
||||||
|
echo "'chore_name' must be a valid chore name like 'mode/gtk_theme', 'misc/foo'."
|
||||||
|
echo "The file extension (.sh) must be discarded."
|
||||||
|
echo "'.reve_repo' is managed by reve, and it's located in '\$reve_installation'."
|
||||||
|
;;
|
||||||
|
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
|
|
||||||
|
|
||||||
if ! grep -q "_reve_completions" "$HOME/.bash_completion"; then
|
|
||||||
echo "$_reve_completions" >> "$HOME/.bash_completion"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! grep -q "_reve_completions" "$HOME/.bash_completion"; then
|
||||||
|
echo "$_reve_completions" >>"$HOME/.bash_completion"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
set_desktop_mode () {
|
set_desktop_mode() {
|
||||||
if [[ -n "$in_desktop_mode" ]]; then
|
local previous_mode num_day num_night current_time
|
||||||
echo "$in_desktop_mode" > "$reve_desktop_mode"
|
previous_mode=$(util_read_config base.desktop_mode)
|
||||||
return 1 # since mode has changed
|
|
||||||
fi
|
|
||||||
|
|
||||||
local previous_mode num_day num_night current_time
|
if [[ -n "$in_desktop_mode" ]]; then
|
||||||
previous_mode=$( util_read_config base.desktop_mode )
|
rt_current_mode="$in_desktop_mode"
|
||||||
num_day=$( awk -F: '{print $1 * 60 + $2}' <<< "$( util_read_config base.time_day )" )
|
echo "$in_desktop_mode" >"$reve_desktop_mode"
|
||||||
num_night=$( awk -F: '{print $1 * 60 + $2}' <<< "$( util_read_config base.time_night )" )
|
else
|
||||||
current_time=$( awk -F: '{print $1 * 60 + $2}' <<< "$(date +%H:%M)" )
|
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)")
|
||||||
|
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"
|
||||||
else
|
else
|
||||||
rt_current_mode="dark"
|
rt_current_mode="dark"
|
||||||
fi
|
fi
|
||||||
|
echo "$rt_current_mode" >"$reve_desktop_mode"
|
||||||
|
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"
|
if [ "$rt_current_mode" == "$previous_mode" ]; then
|
||||||
|
return 0 # since mode did not change
|
||||||
if [ "$rt_current_mode" == "$previous_mode" ]; then
|
else
|
||||||
return 0 # since mode did not change
|
return 1
|
||||||
else
|
fi
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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
|
util_run_chore "mode/$(basename "${file%.sh}")" $rt_current_mode
|
||||||
echo "[reve] [I] Running chore: $( basename "$file" )"
|
done
|
||||||
util_run_chore "$file" $rt_current_mode
|
|
||||||
else
|
|
||||||
echo "[reve] [E] chores_mode: $file is not executable"
|
|
||||||
fi
|
|
||||||
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
|
||||||
|
for arg in "$@"; do
|
||||||
|
if [[ "$arg" == "-d" || "$arg" == "--dark" ]]; then
|
||||||
|
forced_mode="dark"
|
||||||
|
elif [[ "$arg" == "-l" || "$arg" == "--light" ]]; then
|
||||||
|
forced_mode="light"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo $forced_mode
|
||||||
|
}
|
||||||
|
|
||||||
|
f_get_available_chores() {
|
||||||
|
c_ins=0
|
||||||
|
c_ble=0
|
||||||
|
|
||||||
|
while IFS= read -r file; do
|
||||||
|
file=${file#"$reve_installation/.reve_repo/chores/"} && file=${file%.sh}
|
||||||
|
if [ -f "$reve_installation/chores/$file.sh" ]; then
|
||||||
|
echo "☑ $file"
|
||||||
|
((c_ins++))
|
||||||
|
else
|
||||||
|
echo "☐ $file"
|
||||||
|
((c_ble++))
|
||||||
|
fi
|
||||||
|
done < <(find "$reve_installation/.reve_repo/chores" -type f -name "*.sh")
|
||||||
|
|
||||||
|
error I f_get_available_chores "$c_ins installed, $c_ble available"
|
||||||
|
}
|
||||||
|
|
||||||
|
f_add_chore() {
|
||||||
|
# args: $1 -- chore_name
|
||||||
|
# returns: 1 if error, otherwise 0
|
||||||
|
src_file="$reve_installation/.reve_repo/chores/$1.sh"
|
||||||
|
if [ -f "$src_file" ]; then
|
||||||
|
cp "$src_file" "$reve_installation/chores/$1.sh"
|
||||||
|
else
|
||||||
|
error E f_add_chore "there's no chore named '$1' in upstream"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
f_rm_chore() {
|
||||||
|
# args: $1 -- chore_name
|
||||||
|
# returns: 1 if error, otherwise 0
|
||||||
|
target_file="$reve_installation/chores/$1.sh"
|
||||||
|
if [ -f "$target_file" ]; then
|
||||||
|
rm "$target_file"
|
||||||
|
else
|
||||||
|
error E f_rm_chore "there's no chore named '$1' in installation"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
sub_chores() {
|
||||||
|
case $1 in
|
||||||
|
list)
|
||||||
|
echo "installed chores:"
|
||||||
|
find "$reve_installation/chores/" -type f -name "*.sh" | while read -r file; do
|
||||||
|
echo "$file" | awk -F/ '{print " -> "$(NF-1)"/"$NF}'
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
more) f_get_available_chores ;;
|
||||||
|
add) f_add_chore $2 ;;
|
||||||
|
rm) f_rm_chore $2 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
sub_update() {
|
||||||
|
local repo_dir="$reve_installation/.reve_repo"
|
||||||
|
local repo_url="https://git.fybx.dev/fyb/reve.git"
|
||||||
|
|
||||||
|
if [ ! -d "$repo_dir/.git" ]; then
|
||||||
|
error I reve "in sub_update, cloning repository"
|
||||||
|
git clone "$repo_url" "$repo_dir" &>/dev/null
|
||||||
|
else
|
||||||
|
error I reve "in sub_update, pulling changes"
|
||||||
|
git -C "$repo_dir" pull &>/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
error I sub_update "updating all chores"
|
||||||
|
count=0
|
||||||
|
find "$reve_installation/chores/" -type f -name "*.sh" | while read -r file; do
|
||||||
|
file="${file#"$reve_installation/chores/"}"
|
||||||
|
file="${file%".sh"}"
|
||||||
|
echo $file
|
||||||
|
# shellcheck disable=SC2030
|
||||||
|
f_add_chore "$file" && ((count++))
|
||||||
|
done
|
||||||
|
# shellcheck disable=SC2031
|
||||||
|
((count != 0)) && error I sub_update "copied $count files"
|
||||||
|
else
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
if [[ "$arg" == "-d" || "$arg" == "--dark" ]]; then
|
f_add_chore "$arg"
|
||||||
forced_mode="dark"
|
|
||||||
elif [[ "$arg" == "-l" || "$arg" == "--light" ]]; then
|
|
||||||
forced_mode="light"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
echo $forced_mode
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
sub_config () {
|
sub_config() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
get)
|
get)
|
||||||
util_read_config "$2"
|
util_read_config "$2"
|
||||||
;;
|
;;
|
||||||
set)
|
set)
|
||||||
util_write_config "$2" "$3"
|
util_write_config "$2" "$3"
|
||||||
;;
|
;;
|
||||||
rm|delete)
|
rm | delete)
|
||||||
util_delete_config "$2"
|
util_delete_config "$2"
|
||||||
;;
|
;;
|
||||||
"")
|
"")
|
||||||
util_help config
|
util_help config
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "reve: in subcommand config: '$1' is not a valid command"
|
echo "reve: in subcommand config: '$1' is not a valid command"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
main () {
|
main() {
|
||||||
mkdir -p "$reve_folder"
|
mkdir -p "$reve_folder"
|
||||||
|
|
||||||
if [[ "$in_chore_name" != "" ]]; then
|
if [[ "$in_chore_name" != "" ]]; then
|
||||||
forced_mode=$(util_handle_pos "$@")
|
forced_mode=$(util_handle_pos "$@")
|
||||||
util_run_chore "$in_chore_name" $forced_mode
|
util_run_chore "$in_chore_name" $forced_mode
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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 "${@:2}"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
help)
|
chores)
|
||||||
util_help "$2"
|
sub_chores "$2" "$3"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
where)
|
help)
|
||||||
dirname "$( which reve )"
|
util_help "$2"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
shell-completion)
|
where)
|
||||||
in_shell_comp="$2"
|
dirname "$(which reve)"
|
||||||
f_shell_completion
|
exit 0
|
||||||
exit 0
|
;;
|
||||||
;;
|
shell-completion)
|
||||||
mode)
|
in_shell_comp="$2"
|
||||||
in_desktop_mode="$2"
|
f_shell_completion
|
||||||
;;
|
exit 0
|
||||||
reason)
|
;;
|
||||||
in_reason="$2"
|
state)
|
||||||
;;
|
if [ "$2" == "clean" ]; then
|
||||||
chore)
|
util_deleteall_temp
|
||||||
in_chore_name="$2"
|
fi
|
||||||
;;
|
;;
|
||||||
poll)
|
mode)
|
||||||
;;
|
in_desktop_mode="$2"
|
||||||
"")
|
;;
|
||||||
util_help "$2"
|
reason)
|
||||||
exit 0
|
in_reason="$2"
|
||||||
;;
|
;;
|
||||||
*)
|
chore)
|
||||||
echo "reve: invalid command or subcommand: $1"
|
in_chore_name="$2"
|
||||||
exit 1
|
;;
|
||||||
;;
|
poll) ;;
|
||||||
|
"")
|
||||||
|
util_help "$2"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "reve: invalid command or subcommand: $1"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
@@ -6,13 +6,10 @@
|
|||||||
# cp utility/nemo/set_wallpaper.sh ~/.local/share/nemo/scripts
|
# cp utility/nemo/set_wallpaper.sh ~/.local/share/nemo/scripts
|
||||||
# chmod +x ~/.local/share/nemo/scripts/set_wallpaper.sh
|
# chmod +x ~/.local/share/nemo/scripts/set_wallpaper.sh
|
||||||
|
|
||||||
|
# shellcheck source=../../_reve.sh
|
||||||
source "$(reve where)/_reve"
|
source "$(reve where)/_reve"
|
||||||
reve_folder="$HOME/.config/reve"
|
|
||||||
reve_desktop_mode="$reve_folder/desktop_mode"
|
|
||||||
|
|
||||||
mode=$(util_readf "$reve_desktop_mode")
|
mode=$(util_read_config base.desktop_mode)
|
||||||
bgl="$reve_folder/chore/bg_light"
|
|
||||||
bgd="$reve_folder/chore/bg_dark"
|
|
||||||
|
|
||||||
if [ "$NEMO_SCRIPT_SELECTED_FILE_PATHS" = "" ]; then
|
if [ "$NEMO_SCRIPT_SELECTED_FILE_PATHS" = "" ]; then
|
||||||
first=$1
|
first=$1
|
||||||
@@ -20,10 +17,5 @@ else
|
|||||||
first=$(echo "$NEMO_SCRIPT_SELECTED_FILE_PATHS" | head -n 1)
|
first=$(echo "$NEMO_SCRIPT_SELECTED_FILE_PATHS" | head -n 1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$mode" = "dark" ]; then
|
util_write_config "chore.bg_$mode" "$first"
|
||||||
cp -T "$first" "$bgd"
|
reload mode/swww_single "$mode"
|
||||||
else
|
|
||||||
cp -T "$first" "$bgl"
|
|
||||||
fi
|
|
||||||
|
|
||||||
reload mode/swww_single
|
|
||||||
|
|||||||
Reference in New Issue
Block a user