aboutsummaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2025-01-23 19:44:06 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2025-01-23 19:44:06 +0100
commit907cc42f845a18453b9bb5a8bb5fbf5bb556ca22 (patch)
treea787b52dbcbf471539b55a47e35215e446b32a55 /.local
parent5cd8a471287918fe58d2ef4045f1987d0f825518 (diff)
make library functions available to reload.d scripts
Diffstat (limited to '.local')
-rwxr-xr-x.local/share/mode/mode34
-rw-r--r--.local/share/mode/plug.d/10_lib10
-rwxr-xr-x.local/share/mode/reload.d/dunst3
-rw-r--r--.local/share/mode/reload.d/gtk8
-rwxr-xr-x.local/share/mode/reload.d/nvim1
-rwxr-xr-x.local/share/mode/reload.d/polybar2
-rwxr-xr-x.local/share/mode/reload.d/term2
7 files changed, 39 insertions, 21 deletions
diff --git a/.local/share/mode/mode b/.local/share/mode/mode
index 3969fa1..55de32f 100755
--- a/.local/share/mode/mode
+++ b/.local/share/mode/mode
@@ -40,6 +40,24 @@ examples:
EOF
}
+# run a module file
+run_mod() {
+ mod_name="$1"
+
+ # modules must be executable
+ ! [ -x "$mod_name" ] && return
+
+ # parse interpreter from shebang
+ interpreter="$(basename "$(command -v $(head -n1 "$mod_name" | sed -n 's/^#!\(.*\)/\1/p'))")"
+ if [ "$interpreter" = "sh" ] ; then
+ # source module if interpreter is POSIX sh (makes plugin functions available)
+ ( . "$mod_name" )
+ else
+ # else, just run them
+ "$mod_name"
+ fi
+}
+
# generate config files from theme file using scripts in switch.d
switch() {
[ -z "$theme" ] && stupid "error: no theme selected"
@@ -56,20 +74,12 @@ switch() {
# load theme colors + aux variables
. "$theme"
- # load plugins (available to switch.d scripts only)
+ # load plugins (TODO: plugins aren't loaded when only reloading)
for plugin in "$data"/plug.d/* ; do . "$plugin" ; done
# generate new config files / snippets (in parallel)
for switch_function in "$data"/switch.d/* ; do
- ! [ -x "$switch_function" ] && continue
- interpreter="$(basename "$(command -v $(head -n1 "$switch_function" | sed -n 's/^#!\(.*\)/\1/p'))")"
- if [ "$interpreter" = "sh" ] ; then
- # source scripts if they are POSIX sh (makes plugin functions available)
- ( . "$switch_function" ) &
- else
- # else, just run them
- "$switch_function" &
- fi
+ run_mod "$switch_function" &
done
# join all processes started above
@@ -81,8 +91,7 @@ reload() {
echo "reloading programs..."
for reload_function in "$data"/reload.d/* ; do
- ! [ -x "$reload_function" ] && continue
- "$reload_function" &
+ run_mod "$reload_function" &
done
wait $(jobs -p)
@@ -127,6 +136,7 @@ for arg in "$@" ; do
esac
done
+# main
[ $run_cfggen -eq 1 ] && switch
[ $run_reload -eq 1 ] && reload
diff --git a/.local/share/mode/plug.d/10_lib b/.local/share/mode/plug.d/10_lib
index abe75b1..b3a0276 100644
--- a/.local/share/mode/plug.d/10_lib
+++ b/.local/share/mode/plug.d/10_lib
@@ -34,3 +34,13 @@ mkcd() {
cd "$1"
}
+respawn_daemon() {
+ killall -q "$1" && fork "$@"
+}
+
+silent_fail_if_no_commmand() {
+ for name in "$@" ; do
+ [ -z "$(command -v "$name")" ] && exit
+ done
+}
+
diff --git a/.local/share/mode/reload.d/dunst b/.local/share/mode/reload.d/dunst
index 3c09a31..430320c 100755
--- a/.local/share/mode/reload.d/dunst
+++ b/.local/share/mode/reload.d/dunst
@@ -1,4 +1,3 @@
#!/bin/sh
-killall dunst
-fork dunst
+respawn_daemon dunst
diff --git a/.local/share/mode/reload.d/gtk b/.local/share/mode/reload.d/gtk
index a6dbb34..767969d 100644
--- a/.local/share/mode/reload.d/gtk
+++ b/.local/share/mode/reload.d/gtk
@@ -2,9 +2,7 @@
# this is max jank but xfsettingsd does other things besides live gtk theme
# reloading, and i don't like having it running constantly because it fucks
# up fcitx5 and xbindkeys
-(
- fork xfsettingsd --replace
- sleep 1
- killall xfsettingsd
-)
+fork xfsettingsd --replace
+sleep 1
+killall -q xfsettingsd
diff --git a/.local/share/mode/reload.d/nvim b/.local/share/mode/reload.d/nvim
index 84ae847..cfabcc7 100755
--- a/.local/share/mode/reload.d/nvim
+++ b/.local/share/mode/reload.d/nvim
@@ -1,4 +1,5 @@
#!/bin/sh
+silent_fail_if_no_commmand nvr
nvr --serverlist | while read -r nvim_socket ; do
fork nvr --nostart --servername "$nvim_socket" -c 'source $XDG_CONFIG_HOME/nvim/mode.vim'
done
diff --git a/.local/share/mode/reload.d/polybar b/.local/share/mode/reload.d/polybar
index af39394..1976811 100755
--- a/.local/share/mode/reload.d/polybar
+++ b/.local/share/mode/reload.d/polybar
@@ -1,3 +1,3 @@
#!/bin/sh
-polybar-msg cmd restart > /dev/null
+fork polybar-msg cmd restart
diff --git a/.local/share/mode/reload.d/term b/.local/share/mode/reload.d/term
index 5f02463..b711d56 100755
--- a/.local/share/mode/reload.d/term
+++ b/.local/share/mode/reload.d/term
@@ -26,5 +26,5 @@ escape_msgs="$(cat << EOF | tr -d '\n'
EOF
)"
-find /dev/pts -exec sh -c "printf \"$escape_msgs\" > {}" \; 2> /dev/null
+find /dev/pts -exec sh -c "printf '$escape_msgs' > {}" \; 2> /dev/null