]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - shell-completion/bash/journalctl
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / shell-completion / bash / journalctl
index 321d439f0c08757e5a75760510fd870321533ccb..bcd4533a63597b931bd54f2a011e24d26d839124 100644 (file)
@@ -1,8 +1,9 @@
 # journalctl(1) completion                                -*- shell-script -*-
+# SPDX-License-Identifier: LGPL-2.1+
 #
 # This file is part of systemd.
 #
-# Copyright 2010 Ran Benita
+# Copyright © 2010 Ran Benita
 #
 # systemd is free software; you can redistribute it and/or modify it
 # under the terms of the GNU Lesser General Public License as published by
@@ -24,16 +25,11 @@ __contains_word () {
         done
 }
 
-__journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}
-                  ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID} COREDUMP_EXE
-                  _{P,U,G}ID _COMM _EXE _CMDLINE
-                  _CAP_EFFECTIVE _AUDIT_{SESSION,LOGINUID}
-                  _SYSTEMD_{CGROUP,SESSION,{,USER_}UNIT,OWNER_UID,SLICE}
-                  _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP
-                  _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT
-                  _KERNEL_{DEVICE,SUBSYSTEM}
-                  _UDEV_{SYSNAME,DEVNODE,DEVLINK}
-                  __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP)
+__get_machines() {
+        local a b
+        (machinectl list-images --no-legend --no-pager; machinectl list --no-legend --no-pager; echo ".host") | \
+               { while read a b; do echo " $a"; done; } | sort -u;
+}
 
 __syslog_priorities=(emerg alert crit err warning notice info debug)
 
@@ -42,26 +38,26 @@ _journalctl() {
         local -A OPTS=(
                 [STANDALONE]='-a --all --full --system --user
                               --disk-usage -f --follow --header
-                              -h --help -l --local --new-id128 -m --merge --no-pager
-                              --no-tail -q --quiet --setup-keys --this-boot --verify
+                              -h --help -l --local -m --merge --no-pager
+                              --no-tail -q --quiet --setup-keys --verify
                               --version --list-catalog --update-catalog --list-boots
                               --show-cursor --dmesg -k --pager-end -e -r --reverse
                               --utc -x --catalog --no-full --force --dump-catalog
-                              --flush --rotate --sync'
-                       [ARG]='-b --boot --this-boot -D --directory --file -F --field
-                              -o --output -u --unit --user-unit -p --priority
-                              --vacuum-size --vacuum-time'
+                              --flush --rotate --sync --no-hostname -N --fields'
+                       [ARG]='-b --boot -D --directory --file -F --field -t --identifier
+                              -M --machine -o --output -u --unit --user-unit -p --priority
+                              --root --case-sensitive'
                 [ARGUNKNOWN]='-c --cursor --interval -n --lines -S --since -U --until
-                              --after-cursor --verify-key -t --identifier
-                              --root -M --machine'
+                              --after-cursor --verify-key -g --grep
+                              --vacuum-size --vacuum-time --vacuum-files --output-fields'
         )
 
         if __contains_word "$prev" ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then
                 case $prev in
-                        --boot|--this-boot|-b)
+                        --boot|-b)
                                 comps=$(journalctl -F '_BOOT_ID' 2>/dev/null)
                         ;;
-                        --directory|-D)
+                        --directory|-D|--root)
                                 comps=$(compgen -d -- "$cur")
                                 compopt -o filenames
                         ;;
@@ -70,10 +66,13 @@ _journalctl() {
                                 compopt -o filenames
                         ;;
                         --output|-o)
-                                comps='short short-iso short-precise short-monotonic verbose export json json-pretty json-sse cat'
+                                comps=$( journalctl --output=help 2>/dev/null )
                         ;;
                         --field|-F)
-                                comps=${__journal_fields[*]}
+                                comps=$(journalctl --fields | sort 2>/dev/null)
+                       ;;
+                        --machine|-M)
+                                comps=$( __get_machines )
                         ;;
                         --priority|-p)
                                 comps=${__syslog_priorities[*]}
@@ -84,6 +83,12 @@ _journalctl() {
                         --user-unit)
                                 comps=$(journalctl -F '_SYSTEMD_USER_UNIT' 2>/dev/null)
                         ;;
+                        --identifier|-t)
+                                comps=$(journalctl -F 'SYSLOG_IDENTIFIER' 2>/dev/null)
+                        ;;
+                        --case-sensitive)
+                                comps='yes no'
+                        ;;
                         *)
                                 return 0
                         ;;
@@ -116,8 +121,9 @@ _journalctl() {
                 mapfile -t field_vals < <(journalctl -F "${COMP_WORDS[COMP_CWORD-2]}" 2>/dev/null)
                 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "$cur") )
         else
+                mapfile -t field_vals < <(journalctl --fields 2>/dev/null)
                 compopt -o nospace
-                COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") )
+                COMPREPLY=( $(compgen -W '${field_vals[*]}' -S= -- "$cur") )
         fi
 }