]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - shell-completion/bash/journalctl
Merge pull request #9504 from poettering/nss-deadlock
[thirdparty/systemd.git] / shell-completion / bash / journalctl
index 476fe6ba2e0c82f6934fb2ce2ef08722e121a680..48781ee7ce306af44f796bda48fc0451126b4c7c 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,13 @@ __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
-                  _AUDIT_{SESSION,LOGINUID}
-                  _SYSTEMD_{CGROUP,SESSION,UNIT,OWNER_UID}
-                  _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)
 
 _journalctl() {
         local field_vals= cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
@@ -41,20 +39,25 @@ _journalctl() {
                 [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
-                              --version --list-catalog --update-catalog --list-boots'
-                       [ARG]='--boot --this-boot -D --directory --file -F --field
-                              -o --output -u --unit --user-unit'
-                [ARGUNKNOWN]='-c --cursor --interval -n --lines -p --priority --since --until
-                              --verify-key'
+                              --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 --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'
+                [ARGUNKNOWN]='-c --cursor --interval -n --lines -S --since -U --until
+                              --after-cursor --verify-key
+                              --vacuum-size --vacuum-time --vacuum-files --output-fields'
         )
 
         if __contains_word "$prev" ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then
                 case $prev in
-                        --boot|--this-boot)
+                        --boot|-b)
                                 comps=$(journalctl -F '_BOOT_ID' 2>/dev/null)
                         ;;
-                        --directory|-D)
+                        --directory|-D|--root)
                                 comps=$(compgen -d -- "$cur")
                                 compopt -o filenames
                         ;;
@@ -63,10 +66,16 @@ _journalctl() {
                                 compopt -o filenames
                         ;;
                         --output|-o)
-                                comps='short short-monotonic verbose export json cat'
+                                comps='short short-full short-iso short-iso-precise short-precise short-monotonic short-unix verbose export json json-pretty json-sse cat with-unit'
                         ;;
                         --field|-F)
-                                comps=${__journal_fields[*]}
+                                comps=$(journalctl --fields | sort 2>/dev/null)
+                       ;;
+                        --machine|-M)
+                                comps=$( __get_machines )
+                        ;;
+                        --priority|-p)
+                                comps=${__syslog_priorities[*]}
                         ;;
                         --unit|-u)
                                 comps=$(journalctl -F '_SYSTEMD_UNIT' 2>/dev/null)
@@ -74,6 +83,9 @@ _journalctl() {
                         --user-unit)
                                 comps=$(journalctl -F '_SYSTEMD_USER_UNIT' 2>/dev/null)
                         ;;
+                        --identifier|-t)
+                                comps=$(journalctl -F 'SYSLOG_IDENTIFIER' 2>/dev/null)
+                        ;;
                         *)
                                 return 0
                         ;;
@@ -106,8 +118,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
 }