completions/sqlmap: use `_command_exists`

Addresses bash-it/bash-it#1632
pull/1938/head
John D Pell 2021-09-19 10:39:19 -07:00
parent 8a03f451b2
commit fb6e05d915
1 changed files with 9 additions and 8 deletions

View File

@ -1,21 +1,22 @@
#!/bin/bash # shellcheck shell=bash
# ---------------------------------------------------------------------------+ # ---------------------------------------------------------------------------+
# | # |
# Thanks to Alexander Korznikov | # Thanks to Alexander Korznikov |
# http://www.korznikov.com/2014/12/bash-tab-completion-for-awesome-tool.html | # http://www.korznikov.com/2014/12/bash-tab-completion-for-awesome-tool.html |
# | # |
# ---------------------------------------------------------------------------+ # ---------------------------------------------------------------------------+
if command -v sqlmap > /dev/null; then if _command_exists sqlmap
then
_sqlmap() function _sqlmap()
{ {
local cur prev local cur prev
COMPREPLY=() COMPREPLY=()
cur=$(_get_cword) cur="$(_get_cword)"
prev=$(_get_pword) prev="$(_get_pword)"
case $prev in case $prev in
@ -143,7 +144,7 @@ if command -v sqlmap > /dev/null; then
--mobile --page-rank --purge-output --smart \ --mobile --page-rank --purge-output --smart \
--sqlmap-shell --wizard ' --sqlmap-shell --wizard '
COMPREPLY=( $( \ COMPREPLY=( $( \
(while read -d ' ' i; do (while read -d ' ' i; do
[[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] && [[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] &&
continue continue
# flatten array with spaces on either side, # flatten array with spaces on either side,
@ -152,7 +153,7 @@ if command -v sqlmap > /dev/null; then
COMPREPLY=" ${COMPREPLY[@]} " COMPREPLY=" ${COMPREPLY[@]} "
# remove word from list of completions # remove word from list of completions
COMPREPLY=( ${COMPREPLY/ ${i%% *} / } ) COMPREPLY=( ${COMPREPLY/ ${i%% *} / } )
done done
printf '%s ' "${COMPREPLY[@]}") <<<"${COMP_WORDS[@]}" printf '%s ' "${COMPREPLY[@]}") <<<"${COMP_WORDS[@]}"
) ) ) )