[Bash-completion-devel] [PATCH 2/3] ipsec: Add strongSwan specific completion with fallback.

Tobias Brunner tobias at strongswan.org
Thu Aug 4 15:48:35 UTC 2011


If the ipsec command is not provided by strongSwan, completion falls
back to the implementation originally created for FreeS/WAN.
---
 completions/ipsec |   58 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/completions/ipsec b/completions/ipsec
index 4b2a202..2f66da7 100644
--- a/completions/ipsec
+++ b/completions/ipsec
@@ -1,8 +1,8 @@
-# Linux ipsec(8) completion (for FreeS/WAN)
+# Linux ipsec(8) completion (for FreeS/WAN and strongSwan)
 #
 have ipsec || return
 
-_ipsec()
+_ipsec_freeswan()
 {
     local cur prev words cword
     _init_completion || return
@@ -37,8 +37,58 @@ _ipsec()
     esac
 
     return 0
-} &&
-complete -F _ipsec ipsec
+}
+
+_ipsec_strongswan()
+{
+    local cur prev words cword
+    _init_completion || return
+
+    if [ $cword -eq 1 ]; then
+        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
+    fi
+
+    case ${words[1]} in
+        list*)
+            COMPREPLY=( $( compgen -W '--utc' -- "$cur" ) )
+            ;;
+        restart|start)
+            COMPREPLY=( $( compgen -W '--attach-gdb --auto-update --debug \
+                --debug-all --debug-more --nofork' -- "$cur" ) )
+            ;;
+        pki)
+            COMPREPLY=( $( compgen -W '--gen --issue --keyid --print --pub \
+                --req --self --signcrl --verify' -- "$cur" ) )
+            ;;
+        pool)
+            ;;
+        irdumm)
+            _filedir 'rb'
+            ;;
+        *)
+            ;;
+    esac
+
+    return 0
+}
+
+case "$( ipsec --version )" in
+    *strongSwan*)
+        complete -F _ipsec_strongswan ipsec
+        ;;
+    *)
+        complete -F _ipsec_freeswan ipsec
+        ;;
+esac
 
 # Local variables:
 # mode: shell-script
-- 
1.7.4.1




More information about the Bash-completion-devel mailing list