_systemctl.in revision 840b2c0e77911bef3056f358b8d16a3253e4ab70
52ea316008e2581c8113441c9c341e5c65225f6anilgun#compdef systemctl
52ea316008e2581c8113441c9c341e5c65225f6anilgun(( $+functions[_systemctl_command] )) || _systemctl_command()
52ea316008e2581c8113441c9c341e5c65225f6anilgun local -a _systemctl_cmds
52ea316008e2581c8113441c9c341e5c65225f6anilgun _systemctl_cmds=(
52ea316008e2581c8113441c9c341e5c65225f6anilgun "list-sockets:List sockets"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "list-timers:List timers"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "list-units:List units"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "start:Start (activate) one or more units"
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen "stop:Stop (deactivate) one or more units"
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen "reload:Reload one or more units"
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen "restart:Start or restart one or more units"
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen "condrestart:Restart one or more units if active"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "try-restart:Restart one or more units if active"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "reload-or-restart:Reload one or more units if possible, otherwise start or restart"
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen "force-reload:Reload one or more units if possible, otherwise restart if active"
3f08db06526d6901aa08c110b5bc7dde6bc39905nd "hibernate:Hibernate the system"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "hybrid-sleep:Hibernate and suspend the system"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "reload-or-try-restart:Reload one or more units if possible, otherwise restart if active"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "isolate:Start one unit and stop all others"
3f08db06526d6901aa08c110b5bc7dde6bc39905nd "kill:Send signal to processes of a unit"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "is-active:Check whether units are active"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "is-failed:Check whether units are failed"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "status:Show runtime status of one or more units"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "show:Show properties of one or more units/jobs or the manager"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "cat:Show the source unit files and drop-ins"
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung "reset-failed:Reset failed state for all, one, or more units"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "list-unit-files:List installed unit files"
51b60896224b408a35684bd6ec0fafe5e4abe322rbowen "enable:Enable one or more unit files"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "disable:Disable one or more unit files"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "reenable:Reenable one or more unit files"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "preset:Enable/disable one or more unit files based on preset configuration"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "set-default:Set the default target"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "get-default:Query the default target"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "edit:Edit one or more unit files"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "is-system-running:Query overall status of the system"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "help:Show documentation for specified units"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "list-dependencies:Show unit dependency tree"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "mask:Mask one or more units"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "unmask:Unmask one or more units"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "link:Link one or more units files into the search path"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "is-enabled:Check whether unit files are enabled"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "list-jobs:List jobs"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "cancel:Cancel all, one, or more jobs"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "snapshot:Create a snapshot"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "delete:Remove one or more snapshots"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "show-environment:Dump environment"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "set-environment:Set one or more environment variables"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "unset-environment:Unset one or more environment variables"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "daemon-reload:Reload systemd manager configuration"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "daemon-reexec:Reexecute systemd manager"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "default:Enter system default mode"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "rescue:Enter system rescue mode"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "emergency:Enter system emergency mode"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "halt:Shut down and halt the system"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "suspend:Suspend the system"
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh "poweroff:Shut down and power-off the system"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "reboot:Shut down and reboot the system"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "kexec:Shut down and reboot the system with kexec"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "exit:Ask for user instance termination"
52ea316008e2581c8113441c9c341e5c65225f6anilgun "switch-root:Change root directory"
52ea316008e2581c8113441c9c341e5c65225f6anilgun if (( CURRENT == 1 )); then
52ea316008e2581c8113441c9c341e5c65225f6anilgun _describe -t commands 'systemctl command' _systemctl_cmds || compadd "$@"
52ea316008e2581c8113441c9c341e5c65225f6anilgun local curcontext="$curcontext" expl
52ea316008e2581c8113441c9c341e5c65225f6anilgun cmd="${${_systemctl_cmds[(r)$words[1]:*]%%:*}}"
52ea316008e2581c8113441c9c341e5c65225f6anilgun # Deal with any aliases
52ea316008e2581c8113441c9c341e5c65225f6anilgun case $cmd in
52ea316008e2581c8113441c9c341e5c65225f6anilgun condrestart) cmd="try-restart";;
52ea316008e2581c8113441c9c341e5c65225f6anilgun force-reload) cmd="reload-or-try-restart";;
52ea316008e2581c8113441c9c341e5c65225f6anilgun if (( $#cmd )); then
52ea316008e2581c8113441c9c341e5c65225f6anilgun curcontext="${curcontext%:*:*}:systemctl-${cmd}:"
52ea316008e2581c8113441c9c341e5c65225f6anilgun local update_policy
52ea316008e2581c8113441c9c341e5c65225f6anilgun zstyle -s ":completion:${curcontext}:" cache-policy update_policy
52ea316008e2581c8113441c9c341e5c65225f6anilgun if [[ -z "$update_policy" ]]; then
52ea316008e2581c8113441c9c341e5c65225f6anilgun zstyle ":completion:${curcontext}:" cache-policy _systemctl_caching_policy
52ea316008e2581c8113441c9c341e5c65225f6anilgun _call_function ret _systemctl_$cmd || _message 'no more arguments'
52ea316008e2581c8113441c9c341e5c65225f6anilgun _message "unknown systemctl command: $words[1]"
52ea316008e2581c8113441c9c341e5c65225f6anilgun__systemctl()
52ea316008e2581c8113441c9c341e5c65225f6anilgun systemctl $_sys_service_mgr --full --no-legend --no-pager "$@"
52ea316008e2581c8113441c9c341e5c65225f6anilgun# Fills the unit list
52ea316008e2581c8113441c9c341e5c65225f6anilgun_systemctl_all_units()
52ea316008e2581c8113441c9c341e5c65225f6anilgun if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) &&
52ea316008e2581c8113441c9c341e5c65225f6anilgun ! _retrieve_cache SYS_ALL_UNITS;
52ea316008e2581c8113441c9c341e5c65225f6anilgun _sys_all_units=( ${${(f)"$(__systemctl list-units --all)"}%% *} )
52ea316008e2581c8113441c9c341e5c65225f6anilgun _store_cache SYS_ALL_UNITS _sys_all_units
52ea316008e2581c8113441c9c341e5c65225f6anilgun# Fills the unit list including all file units
52ea316008e2581c8113441c9c341e5c65225f6anilgun_systemctl_really_all_units()
52ea316008e2581c8113441c9c341e5c65225f6anilgun local -a all_unit_files;
52ea316008e2581c8113441c9c341e5c65225f6anilgun local -a really_all_units;
52ea316008e2581c8113441c9c341e5c65225f6anilgun if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid SYS_REALLY_ALL_UNITS ) &&
52ea316008e2581c8113441c9c341e5c65225f6anilgun ! _retrieve_cache SYS_REALLY_ALL_UNITS;
52ea316008e2581c8113441c9c341e5c65225f6anilgun all_unit_files=( ${${(f)"$(__systemctl list-unit-files)"}%% *} )
52ea316008e2581c8113441c9c341e5c65225f6anilgun _systemctl_all_units
52ea316008e2581c8113441c9c341e5c65225f6anilgun really_all_units=($_sys_all_units $all_unit_files)
52ea316008e2581c8113441c9c341e5c65225f6anilgun _sys_really_all_units=(${(u)really_all_units})
52ea316008e2581c8113441c9c341e5c65225f6anilgun _store_cache SYS_REALLY_ALL_UNITS _sys_really_all_units
52ea316008e2581c8113441c9c341e5c65225f6anilgun_filter_units_by_property() {
52ea316008e2581c8113441c9c341e5c65225f6anilgun local property=$1 value=$2 ; shift ; shift
52ea316008e2581c8113441c9c341e5c65225f6anilgun local -a units ; units=($*)
52ea316008e2581c8113441c9c341e5c65225f6anilgun local props
52ea316008e2581c8113441c9c341e5c65225f6anilgun for props in ${(ps:\n\n:)"$(_call_program units "$service show --no-pager --property="Id,$property" -- ${units} 2>/dev/null")"}; do
52ea316008e2581c8113441c9c341e5c65225f6anilgun props=(${(f)props})
52ea316008e2581c8113441c9c341e5c65225f6anilgun if [[ "${props[2]}" = "$property=$value" ]]; then
52ea316008e2581c8113441c9c341e5c65225f6anilgun echo -E - " ${props[1]#Id=}"
52ea316008e2581c8113441c9c341e5c65225f6anilgun_systemctl_get_template_names() { echo -E - ${^${(M)${(f)"$(__systemctl list-unit-files)"}##*@.[^[:space:]]##}%%@.*}\@ }
52ea316008e2581c8113441c9c341e5c65225f6anilgun_systemctl_active_units() {_sys_active_units=( ${${(f)"$(__systemctl list-units)"}%% *} )}
52ea316008e2581c8113441c9c341e5c65225f6anilgun_systemctl_startable_units(){
52ea316008e2581c8113441c9c341e5c65225f6anilgun _sys_startable_units=( $( _filter_units_by_property ActiveState inactive $(
52ea316008e2581c8113441c9c341e5c65225f6anilgun _filter_units_by_property CanStart yes $(
52ea316008e2581c8113441c9c341e5c65225f6anilgun __systemctl $mode list-unit-files --state enabled,disabled,static | \
52ea316008e2581c8113441c9c341e5c65225f6anilgun { while read -r a b; do [[ $a =~ @\. ]] || echo -E - " $a"; done; }
52ea316008e2581c8113441c9c341e5c65225f6anilgun __systemctl $mode list-units --state inactive,failed | \
52ea316008e2581c8113441c9c341e5c65225f6anilgun { while read -r a b; do echo -E - " $a"; done; } )) ) )
52ea316008e2581c8113441c9c341e5c65225f6anilgun_systemctl_restartable_units(){
52ea316008e2581c8113441c9c341e5c65225f6anilgun _sys_restartable_units=( $(_filter_units_by_property CanStart yes $(
52ea316008e2581c8113441c9c341e5c65225f6anilgun __systemctl $mode list-unit-files --state enabled,disabled,static | \
52ea316008e2581c8113441c9c341e5c65225f6anilgun { while read -r a b; do [[ $a =~ @\. ]] || echo -E - " $a"; done; }
52ea316008e2581c8113441c9c341e5c65225f6anilgun __systemctl $mode list-units | \
52ea316008e2581c8113441c9c341e5c65225f6anilgun { while read -r a b; do echo -E - " $a"; done; } )) )
52ea316008e2581c8113441c9c341e5c65225f6anilgun_systemctl_failed_units() {_sys_failed_units=( ${${(f)"$(__systemctl list-units --failed)"}%% *} ) }
52ea316008e2581c8113441c9c341e5c65225f6anilgun_systemctl_unit_state() { typeset -gA _sys_unit_state; _sys_unit_state=( $(__systemctl list-unit-files) ) }
52ea316008e2581c8113441c9c341e5c65225f6anilgun# Completion functions for ALL_UNITS
52ea316008e2581c8113441c9c341e5c65225f6anilgunfor fun in is-active is-failed is-enabled status show cat mask preset help list-dependencies edit ; do
52ea316008e2581c8113441c9c341e5c65225f6anilgun (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
52ea316008e2581c8113441c9c341e5c65225f6anilgun _systemctl_really_all_units
52ea316008e2581c8113441c9c341e5c65225f6anilgun _wanted systemd-units expl unit \
52ea316008e2581c8113441c9c341e5c65225f6anilgun compadd "$@" -a - _sys_really_all_units
52ea316008e2581c8113441c9c341e5c65225f6anilgun# Completion functions for ENABLED_UNITS
52ea316008e2581c8113441c9c341e5c65225f6anilgun(( $+functions[_systemctl_disable] )) || _systemctl_disable()
52ea316008e2581c8113441c9c341e5c65225f6anilgun local _sys_unit_state; _systemctl_unit_state
52ea316008e2581c8113441c9c341e5c65225f6anilgun _wanted systemd-units expl 'enabled unit' \
52ea316008e2581c8113441c9c341e5c65225f6anilgun compadd "$@" - ${(k)_sys_unit_state[(R)enabled]}
52ea316008e2581c8113441c9c341e5c65225f6anilgun(( $+functions[_systemctl_reenable] )) || _systemctl_reenable()
52ea316008e2581c8113441c9c341e5c65225f6anilgun local _sys_unit_state; _systemctl_unit_state
52ea316008e2581c8113441c9c341e5c65225f6anilgun _wanted systemd-units expl 'enabled/disabled unit' \
52ea316008e2581c8113441c9c341e5c65225f6anilgun compadd "$@" - ${(k)_sys_unit_state[(R)(enabled|disabled)]} $(_systemctl_get_template_names)
52ea316008e2581c8113441c9c341e5c65225f6anilgun# Completion functions for DISABLED_UNITS
52ea316008e2581c8113441c9c341e5c65225f6anilgun(( $+functions[_systemctl_enable] )) || _systemctl_enable()
52ea316008e2581c8113441c9c341e5c65225f6anilgun local _sys_unit_state; _systemctl_unit_state
52ea316008e2581c8113441c9c341e5c65225f6anilgun _wanted systemd-units expl 'disabled unit' \
52ea316008e2581c8113441c9c341e5c65225f6anilgun compadd "$@" - ${(k)_sys_unit_state[(R)disabled]} $(_systemctl_get_template_names)
52ea316008e2581c8113441c9c341e5c65225f6anilgun# Completion functions for FAILED_UNITS
52ea316008e2581c8113441c9c341e5c65225f6anilgun(( $+functions[_systemctl_reset-failed] )) || _systemctl_reset-failed()
52ea316008e2581c8113441c9c341e5c65225f6anilgun local _sys_failed_units; _systemctl_failed_units
52ea316008e2581c8113441c9c341e5c65225f6anilgun _wanted systemd-units expl 'failed unit' \
52ea316008e2581c8113441c9c341e5c65225f6anilgun compadd "$@" -a - _sys_failed_units || _message "no failed unit found"
52ea316008e2581c8113441c9c341e5c65225f6anilgun# Completion functions for STARTABLE_UNITS
52ea316008e2581c8113441c9c341e5c65225f6anilgun(( $+functions[_systemctl_start] )) || _systemctl_start()
727872d18412fc021f03969b8641810d8896820bhumbedooh local _sys_startable_units; _systemctl_startable_units
0d0ba3a410038e179b695446bb149cce6264e0abnd _wanted systemd-units expl 'startable unit' \
727872d18412fc021f03969b8641810d8896820bhumbedooh compadd "$@" - ${_sys_startable_units[*]} $(_systemctl_get_template_names)
727872d18412fc021f03969b8641810d8896820bhumbedooh# Completion functions for STOPPABLE_UNITS
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedoohfor fun in stop kill try-restart condrestart ; do
727872d18412fc021f03969b8641810d8896820bhumbedooh (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
0d0ba3a410038e179b695446bb149cce6264e0abnd local _sys_active_units; _systemctl_active_units
0d0ba3a410038e179b695446bb149cce6264e0abnd _wanted systemd-units expl 'stoppable unit' \
727872d18412fc021f03969b8641810d8896820bhumbedooh compadd "$@" - $( _filter_units_by_property CanStop yes \
0d0ba3a410038e179b695446bb149cce6264e0abnd ${_sys_active_units[*]} )
0d0ba3a410038e179b695446bb149cce6264e0abnd# Completion functions for ISOLATABLE_UNITS
0d0ba3a410038e179b695446bb149cce6264e0abnd(( $+functions[_systemctl_isolate] )) || _systemctl_isolate()
5effc8b39fae5cd169d17f342bfc265705840014rbowen _systemctl_all_units
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen _wanted systemd-units expl 'isolatable unit' \
0d0ba3a410038e179b695446bb149cce6264e0abnd compadd "$@" - $( _filter_units_by_property AllowIsolate yes \
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd ${_sys_all_units[*]} )
52ea316008e2581c8113441c9c341e5c65225f6anilgun# Completion functions for RELOADABLE_UNITS
'--no-legend[Do not print a legend, i.e. the column headers and the footer with hints]' \
"--no-wall[Don't send wall message before halt/power-off/reboot]" \
'--global[Enable/disable unit files globally]' \
"--no-reload[When enabling/disabling unit files, don't reload daemon configuration]" \