diff options
Diffstat (limited to '.local')
-rwxr-xr-x | .local/share/mode/mode | 34 | ||||
-rw-r--r-- | .local/share/mode/plug.d/10_lib | 10 | ||||
-rwxr-xr-x | .local/share/mode/reload.d/dunst | 3 | ||||
-rw-r--r-- | .local/share/mode/reload.d/gtk | 8 | ||||
-rwxr-xr-x | .local/share/mode/reload.d/nvim | 1 | ||||
-rwxr-xr-x | .local/share/mode/reload.d/polybar | 2 | ||||
-rwxr-xr-x | .local/share/mode/reload.d/term | 2 |
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 |