shell-completion: propose templates for disable/[re]enable/[re]start

Templates can be [re]enabled, on their own if the have DefaultInstance set,
and with an instance suffix in all cases. Propose just the template name
ending in @, to underline the instance suffix may have to be appended.

Likewise for start/restart.

This means that sometimes superflous units that one will not really
want to operate on will be proposed, but this seems better than
proposing a very incomplete set of names.

https://bugs.freedesktop.org/show_bug.cgi?id=66912
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2014-10-14 21:10:02 -04:00
parent f29c77bc01
commit e9a19bd882
2 changed files with 24 additions and 11 deletions

View File

@@ -53,6 +53,9 @@ __filter_units_by_property () {
__get_all_units () { { __systemctl $1 list-unit-files; __systemctl $1 list-units --all; } \
| { while read -r a b; do echo " $a"; done; }; }
__get_template_names () { __systemctl $1 list-unit-files \
| { while read -r a b; do [[ $a =~ @\. ]] && echo " ${a%%@.*}@"; done; }; }
__get_active_units () { __systemctl $1 list-units \
| { while read -r a b; do echo " $a"; done; }; }
__get_startable_units () {
@@ -169,22 +172,26 @@ _systemctl () {
compopt -o filenames
elif __contains_word "$verb" ${VERBS[DISABLED_UNITS]}; then
comps=$( __get_disabled_units $mode )
comps=$( __get_disabled_units $mode;
__get_template_names $mode)
compopt -o filenames
elif __contains_word "$verb" ${VERBS[REENABLABLE_UNITS]}; then
comps=$( __get_disabled_units $mode;
__get_enabled_units $mode )
__get_enabled_units $mode;
__get_template_names $mode)
compopt -o filenames
elif __contains_word "$verb" ${VERBS[STARTABLE_UNITS]}; then
comps=$( __filter_units_by_property $mode CanStart yes \
$( __get_startable_units $mode))
$( __get_startable_units $mode);
__get_template_names $mode)
compopt -o filenames
elif __contains_word "$verb" ${VERBS[RESTARTABLE_UNITS]}; then
comps=$( __filter_units_by_property $mode CanStart yes \
$( __get_restartable_units $mode))
$( __get_restartable_units $mode); \
__get_template_names $mode)
compopt -o filenames
elif __contains_word "$verb" ${VERBS[STOPPABLE_UNITS]}; then