[systemd-commits] 5 commits - shell-completion/bash shell-completion/zsh src/systemctl
Zbigniew Jędrzejewski-Szmek
zbyszek at kemper.freedesktop.org
Wed Oct 29 20:54:46 PDT 2014
shell-completion/bash/systemctl.in | 33 +++++++++++++----------
shell-completion/zsh/_systemctl.in | 28 ++++++++++++++-----
src/systemctl/systemctl.c | 53 +++++++++++++++++++++++++++++--------
3 files changed, 83 insertions(+), 31 deletions(-)
New commits:
commit 81333ecf9d5497f8aa95f7fec23c67b869d5abf9
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Wed Oct 29 23:47:55 2014 -0400
zsh-completion: update start/restart completions
Now zsh should behave the same for those two subcommands as bash.
diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in
index 44981fe..7eefe53 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -141,13 +141,29 @@ _filter_units_by_property() {
done
}
-_systemctl_all_units() { { __systemctl list-unit-files; __systemctl list-units --all; } | { while read -r a b; do echo -E - " $a"; done; } }
+_systemctl_all_units() { { __systemctl list-unit-files; __systemctl list-units --all; } | { while read -r a b; do [[ $a =~ @\. ]] || 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; }) )}
-_systemctl_restartable_units(){_sys_restartable_units=($(__systemctl list-units --state inactive,failed,active -- $(_systemctl_all_units) | { while read -r a b c d; do [[ $b == "loaded" ]] && echo -E - " $a"; done; }) )}
+
+_systemctl_startable_units(){
+ _sys_startable_units=(_filter_units_by_property ActiveState inactive $(
+ _filter_units_by_property CanStart yes $(
+ __systemctl $mode list-unit-files --state enabled,disabled,static | \
+ { while read -r a b; do [[ $a =~ @\. ]] || echo -E - " $a"; done; }
+ __systemctl $mode list-units --state inactive,failed | \
+ { while read -r a b; do echo -E - " $a"; done; } )))
+}
+
+_systemctl_restartable_units(){
+ _sys_restartable_units=(_filter_units_by_property CanStart yes $(
+ __systemctl $mode list-unit-files --state enabled,disabled,static | \
+ { while read -r a b; do [[ $a =~ @\. ]] || echo -E - " $a"; done; }
+ __systemctl $mode list-units | \
+ { while read -r a b; do echo -E - " $a"; done; } ))
+}
+
_systemctl_failed_units() {_sys_failed_units=( $(__systemctl list-units --failed | { while read -r a b; do echo -E - " $a"; done; }) )}
_systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files | { while read -r a b; do [[ $b == "enabled" ]] && echo -E - " $a"; done; }) )}
_systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files | { while read -r a b; do [[ $b == "disabled" ]] && echo -E - " $a"; done; }) )}
@@ -194,8 +210,7 @@ done
(( $+functions[_systemctl_start] )) || _systemctl_start()
{
_systemctl_startable_units
- compadd "$@" - $( _filter_units_by_property CanStart yes \
- ${_sys_startable_units[*]} )
+ compadd "$@" - ${_sys_startable_units[*]} $(_systemctl_get_template_names)
}
# Completion functions for STOPPABLE_UNITS
@@ -231,8 +246,7 @@ for fun in restart reload-or-restart ; do
(( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
{
_systemctl_restartable_units
- compadd "$@" - $( _filter_units_by_property CanStart yes \
- ${_sys_restartable_units[*]} )
+ compadd "$@" - ${_sys_restartable_units[*]} $(_systemctl_get_template_names)
}
done
commit 372b221166eb586c4f767969f442ed940e21f353
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Wed Oct 29 23:06:58 2014 -0400
bash-completion: use improved filtering to make things faster
diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in
index 9e538a9..9e98a18 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -60,14 +60,20 @@ __get_active_units () { __systemctl $1 list-units \
| { while read -r a b; do echo " $a"; done; }; }
__get_startable_units () {
# find startable inactive units
- __filter_units_by_property $mode LoadState loaded $(
- __filter_units_by_property $mode ActiveState inactive $(
- __filter_units_by_property $mode CanStart yes $( __get_all_units )))
+ __filter_units_by_property $mode ActiveState inactive $(
+ __filter_units_by_property $mode CanStart yes $(
+ __systemctl $mode list-unit-files --state enabled,disabled,static | \
+ { while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }
+ __systemctl $mode list-units --state inactive,failed | \
+ { while read -r a b; do echo " $a"; done; } ))
}
__get_restartable_units () {
# filter out masked and not-found
- __filter_units_by_property $mode LoadState loaded $(
- __filter_units_by_property $mode CanStart yes $( __get_all_units ))
+ __filter_units_by_property $mode CanStart yes $(
+ __systemctl $mode list-unit-files --state enabled,disabled,static | \
+ { while read -r a b; do [[ $a =~ @\. ]] || echo " $a"; done; }
+ __systemctl $mode list-units | \
+ { while read -r a b; do echo " $a"; done; } )
}
__get_failed_units () { __systemctl $1 list-units \
| { while read -r a b c d; do [[ $c == "failed" ]] && echo " $a"; done; }; }
commit fec1530e6b5b8d6dc352c7338010357126e84621
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Wed Oct 29 22:51:00 2014 -0400
systemctl: obey --state in list-unit-files
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index b71040b..8481a9b 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -1268,6 +1268,11 @@ next:
return false;
}
+ if (!strv_isempty(arg_states)) {
+ if (!strv_find(arg_states, unit_file_state_to_string(u->state)))
+ return false;
+ }
+
return true;
}
commit 6c71341aeecc3d092ed90f66e1b2c481b8e260ff
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Wed Oct 29 22:46:30 2014 -0400
systemctl: let list-{units,unit-files } honour --type
The docs don't clarify what is expected, but I don't see any reason
why --type should be ignored.
Also restucture the compund conditions into separate clauses for
easier reading.
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 28eaa6a..b71040b 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -301,21 +301,37 @@ static int compare_unit_info(const void *a, const void *b) {
}
static bool output_show_unit(const UnitInfo *u, char **patterns) {
- const char *dot;
-
if (!strv_isempty(patterns)) {
char **pattern;
STRV_FOREACH(pattern, patterns)
if (fnmatch(*pattern, u->id, FNM_NOESCAPE) == 0)
- return true;
+ goto next;
return false;
}
- return (!arg_types || ((dot = strrchr(u->id, '.')) &&
- strv_find(arg_types, dot+1))) &&
- (arg_all || !(streq(u->active_state, "inactive")
- || u->following[0]) || u->job_id > 0);
+next:
+ if (arg_types) {
+ const char *dot;
+
+ dot = strrchr(u->id, '.');
+ if (!dot)
+ return false;
+
+ if (!strv_find(arg_types, dot+1))
+ return false;
+ }
+
+ if (arg_all)
+ return true;
+
+ if (u->job_id > 0)
+ return true;
+
+ if (streq(u->active_state, "inactive") || u->following[0])
+ return false;
+
+ return true;
}
static int output_units_list(const UnitInfo *unit_infos, unsigned c) {
@@ -1231,18 +1247,28 @@ static int compare_unit_file_list(const void *a, const void *b) {
}
static bool output_show_unit_file(const UnitFileList *u, char **patterns) {
- const char *dot;
-
if (!strv_isempty(patterns)) {
char **pattern;
STRV_FOREACH(pattern, patterns)
if (fnmatch(*pattern, basename(u->path), FNM_NOESCAPE) == 0)
- return true;
+ goto next;
return false;
}
- return !arg_types || ((dot = strrchr(u->path, '.')) && strv_find(arg_types, dot+1));
+next:
+ if (!strv_isempty(arg_types)) {
+ const char *dot;
+
+ dot = strrchr(u->path, '.');
+ if (!dot)
+ return false;
+
+ if (!strv_find(arg_types, dot+1))
+ return false;
+ }
+
+ return true;
}
static void output_unit_file_list(const UnitFileList *units, unsigned c) {
commit 9ff8af5460d57dfab78a1137ec743b539715e82a
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Wed Oct 29 22:25:33 2014 -0400
bash-completion: rework startable/restartable units once more
I tried to use 'systemctl --all list-units' to filter unit files, but
this always filters out unit files which are not loaded. We want to complete
systemctl start with those units too, so this approach is not going to work.
New version is rather slow, but hopefully correct.
diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in
index 1c44a8d..9e538a9 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -52,20 +52,23 @@ __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; }; }
+ | { while read -r a b; do [[ $a =~ @\. ]] || 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 () {
- # find inactive or failed units, filter out masked and not-found
- __systemctl $1 list-units --state inactive,failed -- $( __get_all_units ) | \
- { while read -r a b c d; do [[ $b == "loaded" ]] && echo " $a"; done; }; }
+ # find startable inactive units
+ __filter_units_by_property $mode LoadState loaded $(
+ __filter_units_by_property $mode ActiveState inactive $(
+ __filter_units_by_property $mode CanStart yes $( __get_all_units )))
+}
__get_restartable_units () {
- # find !masked, filter out masked and not-found
- __systemctl $1 list-units --state active,inactive,failed -- $( __get_all_units ) | \
- { while read -r a b c d; do [[ $b == "loaded" ]] && echo " $a"; done; }; }
+ # filter out masked and not-found
+ __filter_units_by_property $mode LoadState loaded $(
+ __filter_units_by_property $mode CanStart yes $( __get_all_units ))
+}
__get_failed_units () { __systemctl $1 list-units \
| { while read -r a b c d; do [[ $c == "failed" ]] && echo " $a"; done; }; }
__get_enabled_units () { __systemctl $1 list-unit-files \
@@ -186,15 +189,13 @@ _systemctl () {
compopt -o filenames
elif __contains_word "$verb" ${VERBS[STARTABLE_UNITS]}; then
- comps=$( __filter_units_by_property $mode CanStart yes \
- $( __get_startable_units $mode);
- __get_template_names $mode)
+ comps=$( __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_template_names $mode)
+ comps=$( __get_restartable_units $mode;
+ __get_template_names $mode)
compopt -o filenames
elif __contains_word "$verb" ${VERBS[STOPPABLE_UNITS]}; then
More information about the systemd-commits
mailing list