mirror of
https://github.com/systemd/systemd
synced 2024-07-25 04:05:16 +00:00
bash completion: make systemctl mount-image/bind autocomplete on active services
The verb works only on running service units, so complete on that as the first parameter, and a local file as the second. The other parameters are inside the service namespace so we can't autocomplete from the outside, return early.
This commit is contained in:
parent
79272d3098
commit
c24c63e946
|
@ -62,6 +62,8 @@ __get_template_names () { __systemctl $1 list-unit-files "$2*" \
|
||||||
| { while read -r a b; do [[ $a =~ @\. ]] && echo " ${a%%@.*}@"; done; }; }
|
| { while read -r a b; do [[ $a =~ @\. ]] && echo " ${a%%@.*}@"; done; }; }
|
||||||
__get_active_units () { __systemctl $1 list-units "$2*" \
|
__get_active_units () { __systemctl $1 list-units "$2*" \
|
||||||
| { while read -r a b; do echo " $a"; done; }; }
|
| { while read -r a b; do echo " $a"; done; }; }
|
||||||
|
__get_active_services() { __systemctl $1 list-units "$2*.service" \
|
||||||
|
| { while read -r a b; do echo " $a"; done; }; }
|
||||||
|
|
||||||
__get_not_masked_unit_files() {
|
__get_not_masked_unit_files() {
|
||||||
# filter out masked, not-found, or template units.
|
# filter out masked, not-found, or template units.
|
||||||
|
@ -231,7 +233,7 @@ _systemctl () {
|
||||||
list-timers list-units list-unit-files poweroff
|
list-timers list-units list-unit-files poweroff
|
||||||
reboot rescue show-environment suspend get-default
|
reboot rescue show-environment suspend get-default
|
||||||
is-system-running preset-all list-automounts list-paths'
|
is-system-running preset-all list-automounts list-paths'
|
||||||
[FILE]='link switch-root bind mount-image'
|
[FILE]='link switch-root'
|
||||||
[TARGETS]='set-default'
|
[TARGETS]='set-default'
|
||||||
[MACHINES]='list-machines'
|
[MACHINES]='list-machines'
|
||||||
[LOG_LEVEL]='log-level'
|
[LOG_LEVEL]='log-level'
|
||||||
|
@ -239,6 +241,7 @@ _systemctl () {
|
||||||
[SERVICE_LOG_LEVEL]='service-log-level'
|
[SERVICE_LOG_LEVEL]='service-log-level'
|
||||||
[SERVICE_LOG_TARGET]='service-log-target'
|
[SERVICE_LOG_TARGET]='service-log-target'
|
||||||
[SERVICE_WATCHDOGS]='service-watchdogs'
|
[SERVICE_WATCHDOGS]='service-watchdogs'
|
||||||
|
[MOUNT]='bind mount-image'
|
||||||
)
|
)
|
||||||
|
|
||||||
for ((i=0; i < COMP_CWORD; i++)); do
|
for ((i=0; i < COMP_CWORD; i++)); do
|
||||||
|
@ -385,6 +388,15 @@ _systemctl () {
|
||||||
fi
|
fi
|
||||||
elif __contains_word "$verb" ${VERBS[SERVICE_WATCHDOGS]}; then
|
elif __contains_word "$verb" ${VERBS[SERVICE_WATCHDOGS]}; then
|
||||||
comps='on off'
|
comps='on off'
|
||||||
|
elif __contains_word "$verb" ${VERBS[MOUNT]}; then
|
||||||
|
if __contains_word "$prev" ${VERBS[MOUNT]}; then
|
||||||
|
comps=$( __get_active_services $mode "$cur" )
|
||||||
|
elif [[ "$prev" =~ .service ]]; then
|
||||||
|
comps=$( compgen -A file -- "$cur" )
|
||||||
|
compopt -o filenames
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur_orig") )
|
COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur_orig") )
|
||||||
|
|
Loading…
Reference in a new issue