# Linux ipsec(8) completion (for FreeS/WAN and strongSwan) -*- shell-script -*- # Complete ipsec.conf conn entries. # # Reads a file from stdin in the ipsec.conf(5) format. proc _ipsec_connections { var keyword = '', name = '' while read -r keyword name { if [[ $keyword == [#]* ]] { continue; } [[ $keyword == conn && $name != '%default' ]] && setglobal COMPREPLY = '( '"$name" ) } setglobal COMPREPLY = '( '$( compgen -W '${COMPREPLY[@]}' -- "$cur" ) ) } proc _ipsec_freeswan { var cur = '', prev = '', words = '', cword = '' _init_completion || return if [[ $cword -eq 1 ]] { setglobal COMPREPLY = '( '$( compgen -W 'auto barf eroute klipsdebug look manual pluto ranbits rsasigkey setup showdefaults showhostkey spi spigrp tncfg whack' -- "$cur" ) ) return 0 } match $(words[1]) { with auto setglobal COMPREPLY = '( '$( compgen -W '--asynchronous --up --add --delete --replace --down --route --unroute --ready --status --rereadsecrets' -- "$cur" ) ) with manual setglobal COMPREPLY = '( '$( compgen -W '--up --down --route --unroute --union' \ -- "$cur" ) ) with ranbits setglobal COMPREPLY = '( '$( compgen -W '--quick --continuous --bytes' \ -- "$cur" ) ) with setup setglobal COMPREPLY = '( '$( compgen -W '--start --stop --restart' -- "$cur" ) ) with * } return 0 } proc _ipsec_strongswan { var cur = '', prev = '', words = '', cword = '' _init_completion || return if [[ $cword -eq 1 ]] { setglobal COMPREPLY = '( '$( compgen -W 'down irdumm leases listaacerts listacerts listalgs listall listcacerts listcainfos listcards listcerts listcrls listgroups listocsp listocspcerts listpubkeys openac pki pluto pool purgecerts purgecrls purgeike purgeocsp ready reload rereadaacerts rereadacerts rereadall rereadcacerts rereadcrls rereadgroups rereadocspcerts rereadsecrets restart route scdecrypt scencrypt scepclient secrets start starter status statusall stop stroke unroute uci up update version whack --confdir --copyright --directory --help --version --versioncode' -- "$cur" ) ) return 0 } match $(words[1]) { with down|route|status|statusall|unroute|up var confdir = $[ ipsec --confdir] _ipsec_connections < "$confdir/ipsec.conf" with list* setglobal COMPREPLY = '( '$( compgen -W '--utc' -- "$cur" ) ) with restart|start setglobal COMPREPLY = '( '$( compgen -W '--attach-gdb --auto-update --debug --debug-all --debug-more --nofork' -- "$cur" ) ) with pki setglobal COMPREPLY = '( '$( compgen -W '--gen --issue --keyid --print --pub --req --self --signcrl --verify' -- "$cur" ) ) with pool with irdumm _filedir 'rb' with * } return 0 } match $[ ipsec --version !2 >/dev/null] { with *strongSwan* complete -F _ipsec_strongswan ipsec with * complete -F _ipsec_freeswan ipsec } # ex: ts=4 sw=4 et filetype=sh