From 79272d3098597686d9e796bd946ea272304fd720 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 27 Dec 2023 16:59:03 +0100 Subject: [PATCH 1/4] bash completion: add systemctl service-log-level/target --- shell-completion/bash/systemctl.in | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in index 03c3b70150..ef8cd8f4be 100644 --- a/shell-completion/bash/systemctl.in +++ b/shell-completion/bash/systemctl.in @@ -236,6 +236,8 @@ _systemctl () { [MACHINES]='list-machines' [LOG_LEVEL]='log-level' [LOG_TARGET]='log-target' + [SERVICE_LOG_LEVEL]='service-log-level' + [SERVICE_LOG_TARGET]='service-log-target' [SERVICE_WATCHDOGS]='service-watchdogs' ) @@ -365,6 +367,22 @@ _systemctl () { comps='debug info notice warning err crit alert emerg' elif __contains_word "$verb" ${VERBS[LOG_TARGET]}; then comps='console journal kmsg journal-or-kmsg null' + elif __contains_word "$verb" ${VERBS[SERVICE_LOG_LEVEL]}; then + if __contains_word "$prev" ${VERBS[SERVICE_LOG_LEVEL]}; then + comps=$( __get_all_unit_files $mode "$cur" ) + elif __contains_word "$prev" debug info notice warning err crit alert emerg; then + return 0 + else + comps='debug info notice warning err crit alert emerg' + fi + elif __contains_word "$verb" ${VERBS[SERVICE_LOG_TARGET]}; then + if __contains_word "$prev" ${VERBS[SERVICE_LOG_TARGET]}; then + comps=$( __get_all_unit_files $mode "$cur" ) + elif __contains_word "$prev" console journal kmsg journal-or-kmsg null; then + return 0 + else + comps='console journal kmsg journal-or-kmsg null' + fi elif __contains_word "$verb" ${VERBS[SERVICE_WATCHDOGS]}; then comps='on off' fi From c24c63e94674c877052a327dbca342c0b50b5690 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 27 Dec 2023 17:48:05 +0100 Subject: [PATCH 2/4] 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. --- shell-completion/bash/systemctl.in | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in index ef8cd8f4be..5c444b7fa4 100644 --- a/shell-completion/bash/systemctl.in +++ b/shell-completion/bash/systemctl.in @@ -62,6 +62,8 @@ __get_template_names () { __systemctl $1 list-unit-files "$2*" \ | { while read -r a b; do [[ $a =~ @\. ]] && echo " ${a%%@.*}@"; done; }; } __get_active_units () { __systemctl $1 list-units "$2*" \ | { 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() { # filter out masked, not-found, or template units. @@ -231,7 +233,7 @@ _systemctl () { list-timers list-units list-unit-files poweroff reboot rescue show-environment suspend get-default is-system-running preset-all list-automounts list-paths' - [FILE]='link switch-root bind mount-image' + [FILE]='link switch-root' [TARGETS]='set-default' [MACHINES]='list-machines' [LOG_LEVEL]='log-level' @@ -239,6 +241,7 @@ _systemctl () { [SERVICE_LOG_LEVEL]='service-log-level' [SERVICE_LOG_TARGET]='service-log-target' [SERVICE_WATCHDOGS]='service-watchdogs' + [MOUNT]='bind mount-image' ) for ((i=0; i < COMP_CWORD; i++)); do @@ -385,6 +388,15 @@ _systemctl () { fi elif __contains_word "$verb" ${VERBS[SERVICE_WATCHDOGS]}; then 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 COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur_orig") ) From 5df839e99ffebd873e357837ff0f11b399dd18b2 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 27 Dec 2023 17:49:17 +0100 Subject: [PATCH 3/4] analyze: allow --no-legend with architectures verb It prints a table with a header, allow omitting it Follow-up for fb8cc599ed863502d67 --- src/analyze/analyze.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 005846fdee..6edc412e75 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -597,7 +597,7 @@ static int parse_argv(int argc, char *argv[]) { if (streq_ptr(argv[optind], "condition") && arg_unit && optind < argc - 1) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No conditions can be passed if --unit= is used."); - if ((!arg_legend && !streq_ptr(argv[optind], "plot")) || + if ((!arg_legend && !STRPTR_IN_SET(argv[optind], "plot", "architectures")) || (streq_ptr(argv[optind], "plot") && !arg_legend && !arg_table && FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --no-legend is only supported for plot with either --table or --json=."); From cfb912abaf7ef485c2c11d5e19560233015577fa Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 27 Dec 2023 17:50:36 +0100 Subject: [PATCH 4/4] bash completion: add systemd-analyze architectures Follow-up for fb8cc599ed863502d67 --- shell-completion/bash/systemd-analyze | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/shell-completion/bash/systemd-analyze b/shell-completion/bash/systemd-analyze index 8ecf993571..d27a642220 100644 --- a/shell-completion/bash/systemd-analyze +++ b/shell-completion/bash/systemd-analyze @@ -51,6 +51,10 @@ __get_syscall_sets() { done } +__get_architectures() { + systemd-analyze --no-legend --no-pager architectures | { while read -r a b; do echo " $a"; done } +} + _systemd_analyze() { local i verb comps mode local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword @@ -73,6 +77,7 @@ _systemd_analyze() { [CONDITION]='condition' [INSPECT_ELF]='inspect-elf' [PLOT]='plot' + [ARCHITECTURES]='architectures' ) local CONFIGS='systemd/bootchart.conf systemd/coredump.conf systemd/journald.conf @@ -198,6 +203,13 @@ _systemd_analyze() { if [[ $cur = -* ]]; then comps='--help --version --system --user --global --no-pager --json=off --json=pretty --json=short --table --no-legend' fi + + elif __contains_word "$verb" ${VERBS[ARCHITECTURES]}; then + if [[ $cur = -* ]]; then + comps='--help --version --no-pager --json=off --json=pretty --json=short --no-legend' + else + comps=$( __get_architectures ) + fi fi COMPREPLY=( $(compgen -W '$comps' -- "$cur") )