Created
March 17, 2026 13:26
-
-
Save bebehei/df117397bd30b2bc5a66936d2a316d95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # bash completion for birdc, supporting _most_ command paths, relevant for BGP and some default actions. RIP/OSPF/other protocols explicitly not supported | |
| # License: MIT | |
| _birdc_get_protocol_names() { | |
| birdc show protocols 2>/dev/null | awk 'NR>2 {print $1}' | |
| } | |
| _birdc_completions_show() { | |
| # Only jump into current level, if the current level is already finished | |
| local this_level= | |
| if [ "${COMP_CWORD}" -gt 2 ]; then | |
| this_level="${COMP_WORDS[2]}" | |
| fi | |
| case "$this_level" in | |
| interfaces|interface|interfac|interfa|interf|inter|inte|int|in|i) | |
| COMPREPLY=() | |
| if [ "${COMP_CWORD}" -le 3 ]; then | |
| COMPREPLY=( $(compgen -W "summary" -- "$cur") ) | |
| fi | |
| return 0 | |
| ;; | |
| protocols|protocol|protoco|protoc|proto|prot|pro|pr|p) | |
| include_all_token= | |
| max_length=3 | |
| include_sessions= | |
| if [ "${COMP_CWORD}" -le 3 ]; then | |
| include_all_token=all | |
| fi | |
| if [ "${prev}" = "all" ]; then | |
| max_length=4 | |
| fi | |
| if [ "${COMP_CWORD}" -le "${max_length}" ]; then | |
| include_sessions="$(_birdc_get_protocol_names)" | |
| fi | |
| COMPREPLY=( $(compgen -W "${include_all_token} ${include_sessions}" -- "$cur") ) | |
| return 0 | |
| ;; | |
| symbols|symbol|symbo|symb|sym) | |
| COMPREPLY=( $(compgen -W "table filter function protocol template" -- "$cur") ) | |
| return 0 | |
| ;; | |
| route|rout|rou|ro|r) | |
| # FIXME this is not context aware at all | |
| COMPREPLY=( $(compgen -W "for in table import export filter where all primary filtered export preexport noexport protocol stats count" -- "$cur") ) | |
| return 0 | |
| ;; | |
| esac | |
| COMPREPLY=( $(compgen -W "babel bfd interfaces memory ospf protocols rip route static status symbols" -- "$cur") ) | |
| return 0 | |
| } | |
| _birdc_completions_protocols() { | |
| if [ "${COMP_CWORD}" -le 2 ]; then | |
| COMPREPLY=( $(compgen -W "all $(_birdc_get_protocol_names)" -- "$cur") ) | |
| return 0 | |
| fi | |
| COMPREPLY=() | |
| return 0 | |
| } | |
| _birdc_completions_configure() { | |
| COMPREPLY=( $(compgen -W "soft timeout confirm undo status check" -- "$cur") ) | |
| return 0 | |
| } | |
| _birdc_completions() | |
| { | |
| local cur="${COMP_WORDS[COMP_CWORD]}" | |
| local prev="${COMP_WORDS[COMP_CWORD-1]}" | |
| # Only jump into current level, if the current level is already finished | |
| local top_level= | |
| if [ "${COMP_CWORD}" -gt 1 ]; then | |
| top_level="${COMP_WORDS[1]}" | |
| fi | |
| # Second-level completions | |
| case "$top_level" in | |
| configure) | |
| _birdc_completions_configure | |
| return 0 | |
| ;; | |
| echo) | |
| COMPREPLY=( $(compgen -W "all off debug trace info remote warning error auth" -- "$cur") ) | |
| return 0 | |
| ;; | |
| enable|disable|restart|reload) | |
| _birdc_completions_protocols | |
| return 0 | |
| ;; | |
| show) | |
| _birdc_completions_show | |
| return 0 | |
| ;; | |
| esac | |
| # Intentionally ignored `down`, `graceful restart` commands | |
| COMPREPLY=( $(compgen -W "help show eval echo disable enable restart reload debug mrtdump configure" -- "$cur") ) | |
| return 0 | |
| } | |
| complete -F _birdc_completions birdc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment