aboutsummaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
Diffstat (limited to '.local')
-rwxr-xr-x.local/share/mode/mode58
-rwxr-xr-x.local/share/mode/switch.d/mode2
2 files changed, 38 insertions, 22 deletions
diff --git a/.local/share/mode/mode b/.local/share/mode/mode
index 06ec7dd..83228f1 100755
--- a/.local/share/mode/mode
+++ b/.local/share/mode/mode
@@ -1,11 +1,19 @@
#!/bin/sh
progname="$(basename "$0")"
data="$(dirname "$(readlink -f "$0")")"
-export data
+export data # path to directory containing reload.d, switch.d, etc.
+run_cfggen=1
+run_reload=1
+theme="" # absolute path to theme
+
+# print error message and exit with error
stupid() {
+ echo "$@" >&2
echo "run \`$progname --help\` for options" >&2
+ exit 1
}
+
usage() {
cat << EOF
$progname -- switch system themes
@@ -32,13 +40,17 @@ examples:
EOF
}
+# generate config files from theme file using scripts in switch.d
switch() {
- theme_path="$(readlink -f "$data/themes/$theme")"
- theme="$(basename "$theme_path")"
- echo "setting theme to $theme..."
+ [ -z "$theme" ] && stupid "error: no theme selected"
+ [ ! -e "$theme" ] && stupid "error: theme not found"
+ export theme
+
+ theme_name="$(basename "$theme")"
+ echo "setting theme to $theme_name..."
# load theme colors + aux variables
- . "$theme_path"
+ . "$theme"
# load plugins (available to switch.d scripts only)
for plugin in "$data"/plug.d/* ; do . "$plugin" ; done
@@ -60,6 +72,7 @@ switch() {
wait $(jobs -rp)
}
+# reload programs using scripts in reload.d
reload() {
echo "reloading programs..."
@@ -71,16 +84,25 @@ reload() {
wait $(jobs -rp)
}
-run_cfggen=1
-run_reload=1
-theme=""
-
+# main program argument parser (later argument always take priority)
for arg in "$@" ; do
case "$arg" in
+ # stop parsing arguments after --
--) break ;;
- -h|--help|help) usage ; exit 0 ;;
- restore) theme="$(cat "$XDG_CACHE_HOME/mode/state/theme")" ;;
+ # help
+ -h|--help|help) usage && exit 0 ;;
+ # only run reload scripts
reload) run_reload=1 run_cfggen=0 ;;
+ # prevent reload.d scripts from running
+ -r|--no-reload) run_reload=0 ;;
+ # prevent switch.d scripts from running
+ -c|--no-cfggen) run_cfggen=0 ;;
+ # restore previous theme stored as symlink (see switch.d/mode)
+ restore)
+ theme="$(readlink -f "$XDG_CACHE_HOME/mode/state/theme")"
+ [ ! -e "$theme" ] && stupid "error: could not locate previous theme"
+ ;;
+ # list themes in themes folder
list)
find "$data/themes" -type f,l | while read -r theme ; do
printf '%s' "$(basename "$theme")"
@@ -89,23 +111,17 @@ for arg in "$@" ; do
done
exit 0
;;
- -r|--no-reload) run_reload=0 ;;
- -c|--no-cfggen) run_cfggen=0 ;;
*)
+ # check if unknown argument is a theme name
if [ -e "$data/themes/$arg" ] ; then
- theme="$arg"
+ theme="$(readlink -f "$data/themes/$arg")"
continue
fi
- echo "error: unknown argument or theme: $arg" >&2
- stupid && exit 1
+ # else throw error
+ stupid "error: unknown argument or theme: $arg"
;;
esac
done
-if [ $run_cfggen -eq 1 ] && [ -z "$theme" ] ; then
- echo "error: no theme selected" >&2
- stupid && exit 1
-fi
-export theme
[ $run_cfggen -eq 1 ] && switch
[ $run_reload -eq 1 ] && reload
diff --git a/.local/share/mode/switch.d/mode b/.local/share/mode/switch.d/mode
index 17b981c..3b58fa6 100755
--- a/.local/share/mode/switch.d/mode
+++ b/.local/share/mode/switch.d/mode
@@ -4,5 +4,5 @@ rm -rf "$PREFIX"/*
mkdir -p "$PREFIX"
echo "$mode" > "$PREFIX/mode"
-echo "$theme" > "$PREFIX/theme"
+ln -sf "$theme" "$PREFIX/theme"