Add syncing with extra groups
This commit is contained in:
		
							parent
							
								
									f48b7c8690
								
							
						
					
					
						commit
						ab7c74f888
					
				
					 7 changed files with 23 additions and 18 deletions
				
			
		
							
								
								
									
										2
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
										
									
									
									
								
							|  | @ -17,6 +17,6 @@ generate: get-target output-dir completions | ||||||
| docs: generate | docs: generate | ||||||
| 	BASHLY_SOURCE_DIR=$(TARGET) bashly render :mandoc ./output/man1 | 	BASHLY_SOURCE_DIR=$(TARGET) bashly render :mandoc ./output/man1 | ||||||
| 
 | 
 | ||||||
| deploy: generate docs | install: generate docs | ||||||
| 	cp -f ./output/$(TARGET) ~/.local/bin/ | 	cp -f ./output/$(TARGET) ~/.local/bin/ | ||||||
| 	cp -f ./output/man1/$(TARGET)*.1 ~/.local/share/man/man1/ | 	cp -f ./output/man1/$(TARGET)*.1 ~/.local/share/man/man1/ | ||||||
|  |  | ||||||
|  | @ -19,6 +19,10 @@ commands: | ||||||
|     help: Get the current status of all programs |     help: Get the current status of all programs | ||||||
|   - name: sync |   - name: sync | ||||||
|     help: Remove all programs from autostart and the re-enable all |     help: Remove all programs from autostart and the re-enable all | ||||||
|  |     args: | ||||||
|  |       - name: groups | ||||||
|  |         required: false | ||||||
|  |         help: Extra groups to sync | ||||||
|   - name: enable |   - name: enable | ||||||
|     help: Add a single program to autostart |     help: Add a single program to autostart | ||||||
|     args: |     args: | ||||||
|  |  | ||||||
|  | @ -2,6 +2,5 @@ | ||||||
| 
 | 
 | ||||||
| program=${args[program]:?} | program=${args[program]:?} | ||||||
| 
 | 
 | ||||||
| cmd=$(_get_autostart_cmd "$program") |  | ||||||
| sleep "$(_get_autostart_delay "$program")" | sleep "$(_get_autostart_delay "$program")" | ||||||
| bash -c "$cmd" | bash -c "$(_get_autostart_cmd "$program")" | ||||||
|  |  | ||||||
|  | @ -4,6 +4,6 @@ autostart_units=() | ||||||
| while IFS='' read -r line | while IFS='' read -r line | ||||||
| do | do | ||||||
| 	autostart_units+=("$line") | 	autostart_units+=("$line") | ||||||
| done < <(_list) | done < <(_list "*") | ||||||
| 
 | 
 | ||||||
| _echo_table "${autostart_units[@]}" | column -t -s$'\t' --table-columns 'Unit,Enabled?,Active?,Command' | _echo_table "${autostart_units[@]}" | column -t -s$'\t' --table-columns 'Unit,Enabled?,Active?,Command' | ||||||
|  |  | ||||||
|  | @ -5,16 +5,21 @@ _systemctl () { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| _query_autostart_toml() { | _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( |     '.hosts[$host].groups as $groups | .apps | to_entries[] | select( | ||||||
|         (.value.hosts | contains([$host])) or |         (.value.hosts | contains([$host])) or | ||||||
|         ([.value.group] | inside($groups)) |         ([.value.group] | inside($groups)) or | ||||||
|  |         ([.value.group] | inside($extra_groups)) or | ||||||
|  |         $extra_groups == ["*"] | ||||||
|     ) | '"$1" \ |     ) | '"$1" \ | ||||||
|     "$XDG_CONFIG_HOME/autostart.toml" |     "$XDG_CONFIG_HOME/autostart.toml" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| _list () { | _list () { | ||||||
| 	_query_autostart_toml '.value.alias // .key' | 	_query_autostart_toml '.value.alias // .key' "$1" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| _autostart_run_graphical () { | _autostart_run_graphical () { | ||||||
|  | @ -41,7 +46,7 @@ _autostart_run_graphical () { | ||||||
| _echo_table () { | _echo_table () { | ||||||
| 	for unit in "$@" | 	for unit in "$@" | ||||||
| 	do | 	do | ||||||
| 		if _systemctl "$unit" is-enabled --quiet | 		if [ "$(_systemctl "$unit" is-enabled)" = "enabled" ] | ||||||
| 		then | 		then | ||||||
| 			_enabled=$(green "enabled") | 			_enabled=$(green "enabled") | ||||||
| 		else | 		else | ||||||
|  | @ -64,9 +69,9 @@ _echo_table () { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| _get_autostart_cmd () { | _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 () { | _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' "*" | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,3 +1,3 @@ | ||||||
| #!/usr/bin/env bash | #!/usr/bin/env bash | ||||||
| 
 | 
 | ||||||
| _list | _list "*" | ||||||
|  |  | ||||||
|  | @ -1,14 +1,11 @@ | ||||||
| #!/usr/bin/env bash | #!/usr/bin/env bash | ||||||
| 
 | 
 | ||||||
| rm "$HOME/.config/systemd/user/autostart.target.wants/"* | rm -f "$HOME/.config/systemd/user/autostart.target.wants/"* | ||||||
| 
 | 
 | ||||||
| autostart_units=() | autostart_units=() | ||||||
| while IFS='' read -r line | while IFS='' read -r line | ||||||
| do | do | ||||||
| 	autostart_units+=("$line") | 	autostart_units+=("autostart@$line.service") | ||||||
| done < <(_list) | done < <(_list "${args[groups]:-}") | ||||||
| 
 | 
 | ||||||
| for unit in "${autostart_units[@]}" | systemctl --user add-wants autostart.target "${autostart_units[@]}" | ||||||
| do |  | ||||||
| 	_systemctl "$unit" add-wants autostart.target |  | ||||||
| done |  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue