summaryrefslogtreecommitdiff
path: root/shell-completion
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-10-14 21:10:02 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-10-14 21:20:05 -0400
commite9a19bd882ff8a2c8aef5c63b39525ea231e5fb9 (patch)
tree3e9bd94c53402001487d412d0bf6380dc6775efe /shell-completion
parentf29c77bc0179b0fa57407dbe30b495be9f5ad2e8 (diff)
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
Diffstat (limited to 'shell-completion')
-rw-r--r--shell-completion/bash/systemctl.in15
-rw-r--r--shell-completion/zsh/_systemctl.in20
2 files changed, 24 insertions, 11 deletions
diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in
index bca02310a9..afa80dad72 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -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
diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in
index ca4b899bb3..1435dee724 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -139,6 +139,8 @@ _filter_units_by_property() {
}
_systemctl_all_units() { { __systemctl list-unit-files; __systemctl list-units --all; } | { while read -r a b; do echo -E - " $a"; done; } }
+_systemctl_get_template_names() { __systemctl list-unit-files | { while read -r a b; do [[ $a =~ @\. ]] && echo -E - " ${a%%@.*}@"; done; } }
+
_systemctl_active_units() {_sys_active_units=( $(__systemctl list-units | { while read -r a b; do echo -E - " $a"; done; }) )}
_systemctl_startable_units(){_sys_startable_units=($(__systemctl list-units --state inactive,failed -- $(_systemctl_all_units) | { while read -r a b c d; do [[ $b == "loaded" ]] && echo -E - " $a"; done; }) )}
@@ -158,20 +160,24 @@ for fun in is-active is-failed is-enabled status show cat mask preset help list-
done
# Completion functions for ENABLED_UNITS
-for fun in disable reenable ; do
- (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
- {
+(( $+functions[_systemctl_disable] )) || _systemctl_disable()
+{
+ _systemctl_enabled_units
+ compadd "$@" -a - _sys_enabled_units
+}
+
+(( $+functions[_systemctl_reenable] )) || _systemctl_reenable()
+{
_systemctl_enabled_units
_systemctl_disabled_units
- compadd "$@" -a - _sys_enabled_units _sys_disabled_units
- }
-done
+ compadd "$@" -a - _sys_enabled_units _sys_disabled_units $(_systemctl_get_template_names)
+}
# Completion functions for DISABLED_UNITS
(( $+functions[_systemctl_enable] )) || _systemctl_enable()
{
_systemctl_disabled_units
- compadd "$@" -a - _sys_disabled_units
+ compadd "$@" -a - _sys_disabled_units $(_systemctl_get_template_names)
}
# Completion functions for FAILED_UNITS