Refactor autostart system
This commit is contained in:
parent
b1814d3a5f
commit
0d82914d42
3 changed files with 178 additions and 113 deletions
.bin
|
@ -6,25 +6,17 @@ _systemctl () {
|
|||
systemctl --user "${@:2}" "autostart@$1.service"
|
||||
}
|
||||
|
||||
_dasel () {
|
||||
dasel -f "$HOME/.config/autostart.toml" -r toml -w plain "${@}"
|
||||
_query_autostart_toml() {
|
||||
tomlq -r --arg host "$hostname" \
|
||||
'.hosts[$host].groups as $groups | .apps | to_entries[] | select(
|
||||
(.value.hosts | contains([$host])) or
|
||||
([.value.group] | inside($groups))
|
||||
) | '"$1" \
|
||||
"$HOME/.config/autostart.toml"
|
||||
}
|
||||
|
||||
_list () {
|
||||
part_root='all().filter(not(equal(type(),object))).key()'
|
||||
part_host="all().filter(equal(type(),object)).filter(equal(key(),$hostname)).all().key()"
|
||||
query="merge($part_host,$part_root).all()"
|
||||
programs=$(_dasel "$query" \
|
||||
| sort \
|
||||
| uniq)
|
||||
|
||||
for program in $programs
|
||||
do
|
||||
cmd=$(_get_autostart_cmd "$program")
|
||||
if [ -n "$cmd" ]; then
|
||||
echo "$program"
|
||||
fi
|
||||
done
|
||||
_query_autostart_toml '.key'
|
||||
}
|
||||
|
||||
_echo_table () {
|
||||
|
@ -71,20 +63,7 @@ _autostart_manage_sync () {
|
|||
}
|
||||
|
||||
_get_autostart_cmd () {
|
||||
selector_base="all()"
|
||||
selector_host="all().filter(equal(type(),object)).filter(equal(key(),$hostname)).all()"
|
||||
selector_entry="filter(not(equal(type(),object))).filter(equal(key(),$1))"
|
||||
cmd=$(_dasel "$selector_base.$selector_entry")
|
||||
cmd_local=$(_dasel "$selector_host.$selector_entry")
|
||||
|
||||
if [ -n "$cmd_local" ]; then
|
||||
if [ "$cmd_local" = "false" ]; then
|
||||
cmd=""
|
||||
else
|
||||
cmd="$cmd_local"
|
||||
fi
|
||||
fi
|
||||
echo "$cmd"
|
||||
_query_autostart_toml 'select(.key == "'"$1"'") | .value.command'
|
||||
}
|
||||
|
||||
_autostart_manage_exec () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue