systemd-run revision 8d2bc8e5fd023a24684446f0057440e3fd0d79bf
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas# systemd-run(1) completion -*- shell-script -*-
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas#
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek# This file is part of systemd.
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek#
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek# Copyright 2013 Zbigniew Jędrzejewski-Szmek
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek#
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek# systemd is free software; you can redistribute it and/or modify it
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek# under the terms of the GNU Lesser General Public License as published by
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek# the Free Software Foundation; either version 2.1 of the License, or
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek# (at your option) any later version.
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek#
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek# systemd is distributed in the hope that it will be useful, but
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas# WITHOUT ANY WARRANTY; without even the implied warranty of
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas# General Public License for more details.
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas#
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas# You should have received a copy of the GNU Lesser General Public License
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas# along with systemd; If not, see <http://www.gnu.org/licenses/>.
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas__systemctl() {
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas local mode=$1; shift 1
299c397c127cda34facbe7d089f944a708ec95e9Zbigniew Jędrzejewski-Szmek systemctl $mode --full --no-legend "$@"
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek}
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas__get_slice_units () { __systemctl $1 list-units --all -t slice \
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas | { while read -r a b c d; do echo " $a"; done; }; }
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas__get_machines() {
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas local a b
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek}
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek_systemd_run() {
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek local OPTS='-h --help --version --user --system --scope --unit --description --slice
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek -r --remain-after-exit --send-sighup -H --host -M --machine --service-type
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek --on-active --on-boot --on-startup --on-unit-active --on-unit-inactive
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek --on-calendar --timer-property -t --pty -q --quiet --no-block
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek --uid --gid --nice --setenv -p --property --no-ask-password'
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas local mode=--system
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas local i
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas local opts_with_values=(
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas --unit --description --slice --service-type -H --host -M --machine -p --property --on-active
26bd71f06c842585b184c3c2f29376564102232dRonny Chevalier --on-boot --on-startup --on-unit-active --on-unit-inactive --on-calendar --timer-property
26bd71f06c842585b184c3c2f29376564102232dRonny Chevalier )
26bd71f06c842585b184c3c2f29376564102232dRonny Chevalier for (( i=1; i <= COMP_CWORD; i++ )); do
26bd71f06c842585b184c3c2f29376564102232dRonny Chevalier if [[ ${COMP_WORDS[i]} != -* ]]; then
26bd71f06c842585b184c3c2f29376564102232dRonny Chevalier local root_command=${COMP_WORDS[i]}
26bd71f06c842585b184c3c2f29376564102232dRonny Chevalier _command_offset $i
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas return
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas fi
26bd71f06c842585b184c3c2f29376564102232dRonny Chevalier
26bd71f06c842585b184c3c2f29376564102232dRonny Chevalier [[ ${COMP_WORDS[i]} == "--user" ]] && mode=--user
26bd71f06c842585b184c3c2f29376564102232dRonny Chevalier
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek [[ $i -lt $COMP_CWORD && " ${opts_with_values[@]} " =~ " ${COMP_WORDS[i]} " ]] && ((i++))
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek done
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas
case "$prev" in
--unit|--description|--on-active|--on-boot|--on-startup|--on-unit-active|--on-unit-inactive|--on-calendar)
# argument required but no completions available
return
;;
--slice)
local comps=$(__get_slice_units $mode)
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
;;
--service-type)
local comps='simple forking oneshot dbus notify idle'
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
;;
-p|--property)
local comps='CPUAccounting= MemoryAccounting= BlockIOAccounting= SendSIGHUP=
SendSIGKILL= MemoryLimit= CPUShares= BlockIOWeight= User= Group=
DevicePolicy= KillMode= DeviceAllow= BlockIOReadBandwidth=
BlockIOWriteBandwidth= BlockIODeviceWeight= Nice= Environment=
KillSignal= LimitCPU= LimitFSIZE= LimitDATA= LimitSTACK=
LimitCORE= LimitRSS= LimitNOFILE= LimitAS= LimitNPROC=
LimitMEMLOCK= LimitLOCKS= LimitSIGPENDING= LimitMSGQUEUE=
LimitNICE= LimitRTPRIO= LimitRTTIME= PrivateTmp= PrivateDevices=
PrivateNetwork= NoNewPrivileges= WorkingDirectory= RootDirectory=
TTYPath= SyslogIdentifier= SyslogLevelPrefix= SyslogLevel=
SyslogFacility= TimerSlackNSec='
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
;;
-H|--host)
local comps=$(compgen -A hostname)
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
;;
-M|--machine)
local comps=$( __get_machines )
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
;;
--timer-property)
local comps='AccuracySec= WakeSystem='
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
;;
esac
COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
return 0
}
complete -F _systemd_run systemd-run