summaryrefslogtreecommitdiff
path: root/files
diff options
context:
space:
mode:
authorSteven Hiscocks <steven@hiscocks.me.uk>2014-02-22 16:57:21 +0000
committerSteven Hiscocks <steven@hiscocks.me.uk>2014-02-22 16:57:21 +0000
commit212d05dc0bbea7c776adbc0a9a506cb7e86ae3b9 (patch)
tree912d087b6b261b66e22ead11b04ce37ded71c705 /files
parentcc463aa60da9eac3b20801c90e28e052c76864ad (diff)
downloadfail2ban-212d05dc0bbea7c776adbc0a9a506cb7e86ae3b9.tar.gz
ENH: Add action elements to bash-completion
Diffstat (limited to 'files')
-rw-r--r--files/bash-completion35
1 files changed, 34 insertions, 1 deletions
diff --git a/files/bash-completion b/files/bash-completion
index 7a42bd1e..78ea18fd 100644
--- a/files/bash-completion
+++ b/files/bash-completion
@@ -19,6 +19,15 @@
__fail2ban_jails () {
"$1" status 2>/dev/null | awk -F"\t+" '/Jail list/{print $2}' | sed 's/, / /g'
}
+__fail2ban_jail_actions () {
+ "$1" get "$2" actions 2>/dev/null | sed -n '$s/\([^,]\+\),\?/\1/gp'
+}
+__fail2ban_jail_action_properties () {
+ "$1" get "$2" actionproperties "$3" 2>/dev/null | sed -n '$s/\([^,]\+\),\?/\1/gp'
+}
+__fail2ban_jail_action_methods () {
+ "$1" get "$2" actionmethods "$3" 2>/dev/null | sed -n '$s/\([^,]\+\),\?/\1/gp'
+}
_fail2ban () {
local cur prev words cword
@@ -50,7 +59,7 @@ _fail2ban () {
_filedir
return 0
elif [[ "$1" == *"fail2ban-client" ]];then
- local cmd jail
+ local cmd jail action
case $prev in
"$1")
COMPREPLY=( $( compgen -W \
@@ -80,6 +89,11 @@ _fail2ban () {
cmd="${words[$cword-3]}"
jail="${words[$cword-2]}"
# Handle in section below
+ elif [[ "${words[$cword-4]}" == "set" || "${words[$cword-4]}" == "get" && ${words[$cword-2]} == action* ]];then
+ cmd="${words[$cword-4]}"
+ jail="${words[$cword-3]}"
+ action="${words[$cword-1]}"
+ # Handle in section below
fi
;;
esac
@@ -106,6 +120,25 @@ _fail2ban () {
return 0
;;
esac
+ elif [[ -n "$jail" && -n "$action" ]];then
+ case ${words[$cwords-3]} in
+ action)
+ COMPREPLY=( $( compgen -W \
+ "$( __fail2ban_jail_action_properties "$1" "$jail" "$action")" \
+ -- "$cur" ) )
+ if [[ "$cmd" == "set" ]];then
+ COMPREPLY+=( $(compgen -W "$(__fail2ban_jail_action_methods "$1" "$jail" "$action")" -- "$cur" ) )
+ fi
+ return 0
+ ;;
+ esac
+ elif [[ -n "$jail" && $prev == action* ]];then
+ case $prev in
+ action|actionproperties|actionmethods)
+ COMPREPLY=( $(compgen -W "$(__fail2ban_jail_actions "$1" "$jail")" -- "$cur" ) )
+ return 0
+ ;;
+ esac
elif [[ -n "$jail" && "$cmd" == "set" ]];then
case $prev in
addlogpath)