#compdef systemctl
# SPDX-License-Identifier: LGPL-2.1+
-(( $+functions[_systemctl_command] )) || _systemctl_command()
+(( $+functions[_systemctl_commands] )) || _systemctl_commands()
{
local -a _systemctl_cmds
_systemctl_cmds=(
fi
}
+# @todo _systemd-run has a helper with the same name, so we must redefine
__systemctl()
{
systemctl $_sys_service_mgr --full --no-legend --no-pager "$@" 2>/dev/null
# Fills the unit list
+(( $+functions[_systemctl_all_units] )) ||
_systemctl_all_units()
{
if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS$_sys_service_mgr ) ||
}
# Fills the unit list including all file units
+(( $+functions[_systemctl_really_all_units] )) ||
_systemctl_really_all_units()
{
local -a all_unit_files;
fi
}
+(( $+functions[_filter_units_by_property] )) ||
_filter_units_by_property() {
local property=$1 value=$2; shift 2
local -a units; units=("${(q-)@}")
echo -E - "${(@g:o:)${(k@)props[(Re)$property=$value]}#Id=}"
}
+(( $+functions[_systemctl_get_non_template_names] )) ||
_systemctl_get_non_template_names() { echo -E - ${^${(R)${(f)"$(
__systemctl $mode list-unit-files "$PREFIX*"
__systemctl $mode list-units --all "$PREFIX*"
)"}:#*@.*}%%[[:space:]]*} }
+(( $+functions[_systemctl_get_template_names] )) ||
_systemctl_get_template_names() { echo -E - ${^${(M)${(f)"$(__systemctl list-unit-files "$PREFIX*" )"}##*@.[^[:space:]]##}%%@.*}\@ }
-
+(( $+functions[_systemctl_active_units] )) ||
_systemctl_active_units() {_sys_active_units=( ${${(f)"$(__systemctl list-units "$PREFIX*" )"}%% *} )}
+(( $+functions[_systemctl_startable_units] )) ||
_systemctl_startable_units(){
_sys_startable_units=( $( _filter_units_by_property ActiveState inactive $(
_filter_units_by_property CanStart yes ${${${(f)"$(
)) )
}
+(( $+functions[_systemctl_restartable_units] )) ||
_systemctl_restartable_units(){
_sys_restartable_units=( $( _filter_units_by_property CanStart yes ${${${(f)"$(
__systemctl $mode list-unit-files --state enabled,disabled,static "$PREFIX*"
)"}:#*@.*}%%[[:space:]]*} ) )
}
+(( $+functions[_systemctl_failed_units] )) ||
_systemctl_failed_units() {_sys_failed_units=( ${${(f)"$(__systemctl list-units --state=failed "$PREFIX*" )"}%% *} ) }
+
+(( $+functions[_systemctl_unit_state] )) ||
_systemctl_unit_state() { typeset -gA _sys_unit_state; _sys_unit_state=( $(__systemctl list-unit-files "$PREFIX*" ) ) }
local fun
# emergency exit halt kexec list-jobs list-units
# list-unit-files poweroff reboot rescue show-environment'
+(( $+functions[_systemctl_caching_policy] )) ||
_systemctl_caching_policy()
{
local _sysunits
return 1
}
-_unit_states() {
+(( $+functions[_systemctl_unit_states] )) ||
+_systemctl_unit_states() {
local -a _states
_states=("${(fo)$(__systemctl --state=help)}")
_values -s , "${_states[@]}"
}
-_unit_types() {
+(( $+functions[_systemctl_unit_types] )) ||
+_systemctl_unit_types() {
local -a _types
_types=("${(fo)$(__systemctl -t help)}")
_values -s , "${_types[@]}"
}
-_unit_properties() {
+(( $+functions[_systemctl_unit_properties] )) ||
+_systemctl_unit_properties() {
if ( [[ ${+_sys_all_properties} -eq 0 ]] || _cache_invalid SYS_ALL_PROPERTIES$_sys_service_mgr ) ||
! _retrieve_cache SYS_ALL_PROPERTIES$_sys_service_mgr;
then
_values -s , "${_sys_all_properties[@]}"
}
-_job_modes() {
+(( $+functions[_systemctl_job_modes] )) ||
+_systemctl_job_modes() {
local -a _modes
_modes=(fail replace replace-irreversibly isolate ignore-dependencies ignore-requirements flush)
_values -s , "${_modes[@]}"
_arguments -s \
{-h,--help}'[Show help]' \
'--version[Show package version]' \
- {-t+,--type=}'[List only units of a particular type]:unit type:_unit_types' \
- '--state=[Display units in the specified state]:unit state:_unit_states' \
- '--job-mode=[Specify how to deal with other jobs]:mode:_job_modes' \
- {-p+,--property=}'[Show only properties by specific name]:unit property:_unit_properties' \
+ {-t+,--type=}'[List only units of a particular type]:unit type:_systemctl_unit_types' \
+ '--state=[Display units in the specified state]:unit state:_systemctl_unit_states' \
+ '--job-mode=[Specify how to deal with other jobs]:mode:_systemctl_job_modes' \
+ {-p+,--property=}'[Show only properties by specific name]:unit property:_systemctl_unit_properties' \
{-a,--all}'[Show all units/properties, including dead/empty ones]' \
'--reverse[Show reverse dependencies]' \
'--after[Show units ordered after]' \
'--firmware-setup[Tell the firmware to show the setup menu on next boot]' \
'--plain[When used with list-dependencies, print output as a list]' \
'--failed[Show failed units]' \
- '*::systemctl command:_systemctl_command'
+ '*::systemctl command:_systemctl_commands'