X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=bash-completion%2Fsystemd-bash-completion.sh;h=5f829b36aefd94a93cc8543befca062bc622b6e5;hb=924ee2cb0caa0c116ff6cf8c16f54588c4d4a4d8;hp=d6adfce0eaf1decaf527489694076bf5ad17b571;hpb=b80f194eea3e2757966118cadf218354b11bf5da;p=elogind.git diff --git a/bash-completion/systemd-bash-completion.sh b/bash-completion/systemd-bash-completion.sh index d6adfce0e..5f829b36a 100644 --- a/bash-completion/systemd-bash-completion.sh +++ b/bash-completion/systemd-bash-completion.sh @@ -122,7 +122,7 @@ _systemctl () { for ((i=0; $i <= $COMP_CWORD; i++)); do if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} && - ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG}]}; then + ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then verb=${COMP_WORDS[i]} break fi @@ -245,7 +245,7 @@ _loginctl () { for ((i=0; $i <= $COMP_CWORD; i++)); do if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} && - ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG}]}; then + ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then verb=${COMP_WORDS[i]} break fi @@ -280,6 +280,17 @@ _loginctl () { } complete -F _loginctl loginctl +__journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC} + ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID} + _{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) + _journalctl() { local field_vals= cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} local -A OPTS=( @@ -291,17 +302,6 @@ _journalctl() { [ARGUNKNOWN]='-c --cursor --interval -n --lines -p --priority --since --until --verify-key' ) - local journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC} - ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID} - _{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) - if __contains_word "$prev" ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then case $prev in @@ -313,7 +313,7 @@ _journalctl() { comps='short short-monotonic verbose export json cat' ;; --field|-F) - comps=${journal_fields[*]} + comps=${__journal_fields[*]} ;; --unit|-u) comps=$(journalctl -F '_SYSTEMD_UNIT') @@ -337,11 +337,57 @@ _journalctl() { COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "$cur") ) else compopt -o nospace - COMPREPLY=( $(compgen -W '${journal_fields[*]}' -S= -- "$cur") ) + COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") ) fi } complete -F _journalctl journalctl +_coredumpctl() { + local i verb comps + local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} + local OPTS='-h --help --version --no-pager --no-legend -o --output -F --field' + + local -A VERBS=( + [LIST]='list' + [DUMP]='dump' + ) + + if __contains_word "$prev" '--output -o'; then + comps=$( compgen -A file -- "$cur" ) + compopt -o filenames + elif __contains_word "$prev" '--FIELD -F'; then + comps=$( compgen -W '${__journal_fields[*]}' -- "$cur" ) + elif [[ $cur = -* ]]; then + comps=${OPTS} + elif __contains_word "$prev" ${VERBS[*]} && + ! __contains_word ${COMP_WORDS[COMP_CWORD-2]} '--output -o -F --field'; then + compopt -o nospace + COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") ) + return 0 + elif [[ $cur = *=* ]]; then + mapfile -t field_vals < <(systemd-coredumpctl -F "${prev%=}" 2>/dev/null) + COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur#=}") ) + return 0 + else + for ((i=0; i <= COMP_CWORD; i++)); do + if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then + verb=${COMP_WORDS[i]} + break + fi + done + + if [[ -z $verb ]]; then + comps=${VERBS[*]} + elif __contains_word "$verb" ${VERBS[LIST]} ${VERBS[DUMP]}; then + comps='' + fi + fi + + COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) + return 0 +} +complete -F _coredumpctl systemd-coredumpctl + _timedatectl() { local i verb comps local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} @@ -476,3 +522,81 @@ _hostnamectl() { return 0 } complete -F _hostnamectl hostnamectl + +__get_all_sysdevs() { + local -a devs=(/sys/bus/*/devices/*/ /sys/class/*/*/) + printf '%s\n' "${devs[@]%/}" +} + +_udevadm() { + local i verb comps + local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} + local OPTS='-h --help --version --debug' + + local -A VERBS=( + [INFO]='info' + [TRIGGER]='trigger' + [SETTLE]='settle' + [CONTROL]='control' + [MONITOR]='monitor' + [HWDB]='hwdb' + [TESTBUILTIN]='test-builtin' + [TEST]='test' + ) + + for ((i=0; $i <= $COMP_CWORD; i++)); do + if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} && + ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then + verb=${COMP_WORDS[i]} + break + fi + done + + if [[ -z $verb && $cur = -* ]]; then + COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) + return 0 + fi + + if [[ -z $verb ]]; then + comps=${VERBS[*]} + + elif __contains_word "$verb" ${VERBS[INFO]}; then + if [[ $cur = -* ]]; then + comps='--help --query= --path= --name= --root --attribute-walk --export-db --cleanup-db' + else + comps=$( __get_all_sysdevs ) + fi + + elif __contains_word "$verb" ${VERBS[TRIGGER]}; then + comps='--help --verbose --dry-run --type= --action= --subsystem-match= + --subsystem-nomatch= --attr-match= --attr-nomatch= --property-match= + --tag-match= --sysname-match= --parent-match=' + + elif __contains_word "$verb" ${VERBS[SETTLE]}; then + comps='--help --timeout= --seq-start= --seq-end= --exit-if-exists= --quiet' + + elif __contains_word "$verb" ${VERBS[CONTROL]}; then + comps='--help --exit --log-priority= --stop-exec-queue --start-exec-queue + --reload --property= --children-max= --timeout=' + + elif __contains_word "$verb" ${VERBS[MONITOR]}; then + comps='--help --kernel --udev --property --subsystem-match= --tag-match=' + + elif __contains_word "$verb" ${VERBS[HWDB]}; then + comps='--help --update --test=' + + elif __contains_word "$verb" ${VERBS[TEST]}; then + if [[ $cur = -* ]]; then + comps='--help --action=' + else + comps=$( __get_all_sysdevs ) + fi + + elif __contains_word "$verb" ${VERBS[TESTBUILTIN]}; then + comps='blkid btrfs firmware hwdb input_id kmod path_id usb_id uaccess' + fi + + COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) + return 0 +} +complete -F _udevadm udevadm