/usr/share/bash-completion/completions/drbdadm is in drbd-utils 8.9.10-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | #
# /etc/bash_completion.d/drbdadm
#
# Bash completion for the DRBD top-level management application, drbdadm.
#
# If you have bash completion enabled, this module will
#
# - provide tab completion for drbdadm sub-commands (up, down, primary,
# secondary etc.);
#
# - try to detect your current resource state and provide appropriate
# command completion for the sub-command you provided. For example,
# when if you have entered the "primary" sub-command, it will list
# only those resources that are currently in the Secondary role;
#
# - differentiate between stacked and unstacked resources.
#
# This module does NOT guarantee that the DRBD state engine will in
# fact agree to do what you ask it to. For example, resources that are
# currently Primary and not connected are not excluded from the
# completion list for the "detach" sub-command.
#
# Finally, this module is only capable of parsing resources correctly
# if you are using the default location for your DRBD configuration
# file (/etc/drbd.conf).
__drbdadm_all_resources() {
# Detects all resources currently listed in drbd.conf
local resources="$(${DRBDADM} sh-resources) all"
COMPREPLY=( $(compgen -W "$resources" -- "$current") )
}
__drbdadm_resources_by_status() {
# Detects only those resources that match a particular status
local status_type="$1"
shift 1
local status_filter="$*"
local resources="$(${DRBDADM} sh-resources)"
local filtered_resources
local res
for res in $resources; do
local resource_status="$(${DRBDADM} $status_type $res 2>/dev/null)"
# In case of multiple volumes, consider only the first line
set -- $resource_status
resource_status=$1
local i
for i in $status_filter; do
if [ "${resource_status%%/*}" = $i ]; then
filtered_resources="$filtered_resources $res"
fi
done
done
COMPREPLY=( $(compgen -W "$filtered_resources" -- "$current") )
}
__drbdadm_commands() {
# Lists drbdadm sub-commands
COMPREPLY=( $(compgen -W "$drbdadm_command_list" -- "$current") )
}
__drbdadm_options() {
# Lists global drbdadm options
local options='-d --dry-run -v --verbose -S --stacked -t --config-to-test'
COMPREPLY=( $(compgen -W "$options" -- "$current") )
}
__drbdadm_subcmd_options() {
local subcmd="$1"
local options=($(drbdadm help $subcmd | sed -e '1,/OPTIONS FOR/ d;/^$/,$ d;s/ \(--[a-z-]*\).*/\1/'))
local filtered
local o have
for o in ${options[@]}; do
for have in ${COMP_WORDS[@]}; do
[[ $o = "$have" ]] && continue 2
done
filtered="$filtered $o"
done
COMPREPLY=( $(compgen -W "$filtered" -- "$current") )
}
_drbdadm() {
local DRBDADM="env DRBD_DONT_WARN_ON_VERSION_MISMATCH=1 ${COMP_WORDS[0]}"
local drbdadm_command_list=' attach disk-options detach connect net-options disconnect up resource-options down primary secondary invalidate invalidate-remote outdate verify pause-sync resume-sync resize adjust wait-connect role cstate dstate dump wait-connect wait-con-int create-md dump-md wipe-md get-gi show-gi help apply-al hidden-commands '
# Redefine the drbdadm we use in __drbdadm_all_resources and
# __drbdadm_resources_by_status, if running in stacked mode
case "$COMP_LINE " in
*" -S "*|*" --stacked "*)
DRBDADM="$DRBDADM --stacked"
;;
esac
local current previous
# The word currently being evaluated for completion
current=${COMP_WORDS[COMP_CWORD]}
# The word that precedes the currently-evaluated one
previous=${COMP_WORDS[COMP_CWORD-1]}
case "$previous" in
drbdadm)
case "$current" in
-*)
__drbdadm_options
;;
*)
__drbdadm_commands
;;
esac
;;
primary)
__drbdadm_resources_by_status "role" "Secondary"
;;
secondary)
__drbdadm_resources_by_status "role" "Primary"
;;
detach|disk-options)
__drbdadm_resources_by_status "dstate" "UpToDate" "Inconsistent" "Outdated"
;;
outdate)
__drbdadm_resources_by_status "dstate" "UpToDate"
;;
attach|apply-al)
__drbdadm_resources_by_status "dstate" "Diskless" "Unconfigured"
;;
connect)
__drbdadm_resources_by_status "cstate" "StandAlone" "Unconfigured"
;;
invalidate-remote)
__drbdadm_resources_by_status "cstate" "Connected"
;;
disconnect|net-options)
__drbdadm_resources_by_status "cstate" "Connected" "WFConnection" "VerifyT" "VerifyS"
;;
verify)
__drbdadm_resources_by_status "cstate" "Connected"
;;
pause-sync)
__drbdadm_resources_by_status "cstate" "SyncSource" "SyncTarget"
;;
resume-sync)
__drbdadm_resources_by_status "cstate" "PausedSyncS" "PausedSyncT"
;;
*)
if (( COMP_CWORD > 2 )); then
local subcmd
subcmd=${COMP_WORDS[1]}
case "$drbdadm_command_list" in
*" $subcmd "*)
__drbdadm_subcmd_options $subcmd
;;
esac
else
__drbdadm_all_resources
fi
;;
esac
}
complete -o default -F _drbdadm drbdadm
|