diff --git a/Makefile b/Makefile index b2a84de..35835aa 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,6 @@ generate: get-target output-dir completions docs: generate BASHLY_SOURCE_DIR=$(TARGET) bashly render :mandoc ./output/man1 -deploy: generate docs +install: generate docs cp -f ./output/$(TARGET) ~/.local/bin/ cp -f ./output/man1/$(TARGET)*.1 ~/.local/share/man/man1/ diff --git a/autostart-manage/bashly.yml b/autostart-manage/bashly.yml index 229eb11..72f5d1a 100644 --- a/autostart-manage/bashly.yml +++ b/autostart-manage/bashly.yml @@ -19,6 +19,10 @@ commands: help: Get the current status of all programs - name: sync help: Remove all programs from autostart and the re-enable all + args: + - name: groups + required: false + help: Extra groups to sync - name: enable help: Add a single program to autostart args: diff --git a/autostart-manage/exec_command.sh b/autostart-manage/exec_command.sh index 2842069..2e2c816 100644 --- a/autostart-manage/exec_command.sh +++ b/autostart-manage/exec_command.sh @@ -2,6 +2,5 @@ program=${args[program]:?} -cmd=$(_get_autostart_cmd "$program") sleep "$(_get_autostart_delay "$program")" -bash -c "$cmd" +bash -c "$(_get_autostart_cmd "$program")" diff --git a/autostart-manage/info_command.sh b/autostart-manage/info_command.sh index 1f895e3..566cdce 100644 --- a/autostart-manage/info_command.sh +++ b/autostart-manage/info_command.sh @@ -4,6 +4,6 @@ autostart_units=() while IFS='' read -r line do autostart_units+=("$line") -done < <(_list) +done < <(_list "*") _echo_table "${autostart_units[@]}" | column -t -s$'\t' --table-columns 'Unit,Enabled?,Active?,Command' diff --git a/autostart-manage/lib/common.sh b/autostart-manage/lib/common.sh index 2479fe1..266c6e7 100644 --- a/autostart-manage/lib/common.sh +++ b/autostart-manage/lib/common.sh @@ -5,16 +5,21 @@ _systemctl () { } _query_autostart_toml() { - tomlq -r --arg host "$HOSTNAME" \ + groups_json=$(echo -n "$2" | tr "," "\n" | jq -R . | jq -s .) + tomlq -r \ + --arg host "$HOSTNAME" \ + --argjson extra_groups "$groups_json" \ '.hosts[$host].groups as $groups | .apps | to_entries[] | select( (.value.hosts | contains([$host])) or - ([.value.group] | inside($groups)) + ([.value.group] | inside($groups)) or + ([.value.group] | inside($extra_groups)) or + $extra_groups == ["*"] ) | '"$1" \ "$XDG_CONFIG_HOME/autostart.toml" } _list () { - _query_autostart_toml '.value.alias // .key' + _query_autostart_toml '.value.alias // .key' "$1" } _autostart_run_graphical () { @@ -41,7 +46,7 @@ _autostart_run_graphical () { _echo_table () { for unit in "$@" do - if _systemctl "$unit" is-enabled --quiet + if [ "$(_systemctl "$unit" is-enabled)" = "enabled" ] then _enabled=$(green "enabled") else @@ -64,9 +69,9 @@ _echo_table () { } _get_autostart_cmd () { - _query_autostart_toml 'select((.key == "'"$1"'") or (.value.alias == "'"$1"'")) | .value.command' + _query_autostart_toml 'select((.key == "'"$1"'") or (.value.alias == "'"$1"'")) | .value.command' "*" } _get_autostart_delay () { - _query_autostart_toml 'select((.key == "'"$1"'") or (.value.alias == "'"$1"'")) | .value.delay // 0' + _query_autostart_toml 'select((.key == "'"$1"'") or (.value.alias == "'"$1"'")) | .value.delay // 0' "*" } diff --git a/autostart-manage/list_command.sh b/autostart-manage/list_command.sh index 0986740..c732452 100644 --- a/autostart-manage/list_command.sh +++ b/autostart-manage/list_command.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -_list +_list "*" diff --git a/autostart-manage/sync_command.sh b/autostart-manage/sync_command.sh index d08ac71..49dfd4e 100644 --- a/autostart-manage/sync_command.sh +++ b/autostart-manage/sync_command.sh @@ -1,14 +1,11 @@ #!/usr/bin/env bash -rm "$HOME/.config/systemd/user/autostart.target.wants/"* +rm -f "$HOME/.config/systemd/user/autostart.target.wants/"* autostart_units=() while IFS='' read -r line do - autostart_units+=("$line") -done < <(_list) + autostart_units+=("autostart@$line.service") +done < <(_list "${args[groups]:-}") -for unit in "${autostart_units[@]}" -do - _systemctl "$unit" add-wants autostart.target -done +systemctl --user add-wants autostart.target "${autostart_units[@]}"