completion/sqlmap: simplify code flow (whitespace)

Convert from indented if-block to return then unindented code. This should have basically one line change at the top, one line removed at the bottom, and then all whitespace.

Apply `shfmt`, but `shellcheck` is an absolute mess, so don't add to `clean_files.txt` yet.
pull/1962/head
John D Pell 2021-09-19 10:40:27 -07:00 committed by John D Pell
parent 4dbe92e38d
commit c4e4846ae5
1 changed files with 148 additions and 152 deletions

View File

@ -7,162 +7,158 @@
# | # |
# ---------------------------------------------------------------------------+ # ---------------------------------------------------------------------------+
if _command_exists sqlmap _command_exists sqlmap || return
then
function _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
# List directory content # List directory content
--tamper) --tamper)
COMPREPLY=( $( compgen -W "$tamper" -- "$cur" ) ) COMPREPLY=($(compgen -W "$tamper" -- "$cur"))
return 0 return 0
;; ;;
--output-dir|-t|-l|-m|-r|--load-cookies|--proxy-file|--sql-file|--shared-lib|--file-write) --output-dir | -t | -l | -m | -r | --load-cookies | --proxy-file | --sql-file | --shared-lib | --file-write)
_filedir _filedir
return 0 return 0
;; ;;
-c) -c)
_filedir ini _filedir ini
return 0 return 0
;; ;;
--method) --method)
COMPREPLY=( $( compgen -W 'GET POST PUT' -- "$cur" ) ) COMPREPLY=($(compgen -W 'GET POST PUT' -- "$cur"))
return 0 return 0
;; ;;
--auth-type) --auth-type)
COMPREPLY=( $( compgen -W 'Basic Digest NTLM PKI' -- "$cur" ) ) COMPREPLY=($(compgen -W 'Basic Digest NTLM PKI' -- "$cur"))
return 0 return 0
;; ;;
--tor-type) --tor-type)
COMPREPLY=( $( compgen -W 'HTTP SOCKS4 SOCKS5' -- "$cur" ) ) COMPREPLY=($(compgen -W 'HTTP SOCKS4 SOCKS5' -- "$cur"))
return 0 return 0
;; ;;
-v) -v)
COMPREPLY=( $( compgen -W '1 2 3 4 5 6' -- "$cur" ) ) COMPREPLY=($(compgen -W '1 2 3 4 5 6' -- "$cur"))
return 0 return 0
;; ;;
--dbms) --dbms)
COMPREPLY=( $( compgen -W 'mysql mssql access postgres' -- "$cur" ) ) COMPREPLY=($(compgen -W 'mysql mssql access postgres' -- "$cur"))
return 0 return 0
;; ;;
--level|--crawl) --level | --crawl)
COMPREPLY=( $( compgen -W '1 2 3 4 5' -- "$cur" ) ) COMPREPLY=($(compgen -W '1 2 3 4 5' -- "$cur"))
return 0 return 0
;; ;;
--risk) --risk)
COMPREPLY=( $( compgen -W '0 1 2 3' -- "$cur" ) ) COMPREPLY=($(compgen -W '0 1 2 3' -- "$cur"))
return 0 return 0
;; ;;
--technique) --technique)
COMPREPLY=( $( compgen -W 'B E U S T Q' -- "$cur" ) ) COMPREPLY=($(compgen -W 'B E U S T Q' -- "$cur"))
return 0 return 0
;; ;;
-s) -s)
_filedir sqlite _filedir sqlite
return 0 return 0
;; ;;
--dump-format) --dump-format)
COMPREPLY=( $( compgen -W 'CSV HTML SQLITE' -- "$cur" ) ) COMPREPLY=($(compgen -W 'CSV HTML SQLITE' -- "$cur"))
return 0 return 0
;; ;;
-x) -x)
_filedir xml _filedir xml
return 0 return 0
;; ;;
esac esac
if [[ "$cur" == * ]]; then if [[ "$cur" == * ]]; then
COMPREPLY=( $( compgen -W '-h --help -hh --version -v -d -u --url -l -x -m -r -g -c --method \ COMPREPLY=($(compgen -W '-h --help -hh --version -v -d -u --url -l -x -m -r -g -c --method \
--data --param-del --cookie --cookie-del --load-cookies \ --data --param-del --cookie --cookie-del --load-cookies \
--drop-set-cookie --user-agent --random-agent --host --referer \ --drop-set-cookie --user-agent --random-agent --host --referer \
--headers --auth-type --auth-cred --auth-private --ignore-401 \ --headers --auth-type --auth-cred --auth-private --ignore-401 \
--proxy --proxy-cred --proxy-file --ignore-proxy --tor --tor-port \ --proxy --proxy-cred --proxy-file --ignore-proxy --tor --tor-port \
--tor-type --check-tor --delay --timeout --retries --randomize \ --tor-type --check-tor --delay --timeout --retries --randomize \
--safe-url --safe-freq --skip-urlencode --csrf-token --csrf-url \ --safe-url --safe-freq --skip-urlencode --csrf-token --csrf-url \
--force-ssl --hpp --eval -o --predict-output --keep-alive \ --force-ssl --hpp --eval -o --predict-output --keep-alive \
--null-connection --threads -p --skip --dbms --dbms-cred \ --null-connection --threads -p --skip --dbms --dbms-cred \
--os --invalid-bignum --invalid-logical --invalid-string \ --os --invalid-bignum --invalid-logical --invalid-string \
--no-cast --no-escape --prefix --suffix --tamper --level \ --no-cast --no-escape --prefix --suffix --tamper --level \
--risk --string --not-string --regexp --code --text-only \ --risk --string --not-string --regexp --code --text-only \
--titles --technique --time-sec --union-cols --union-char \ --titles --technique --time-sec --union-cols --union-char \
--union-from --dns-domain --second-order -f --fingerprint \ --union-from --dns-domain --second-order -f --fingerprint \
-a --all -b --banner --current-user --current-db --hostname \ -a --all -b --banner --current-user --current-db --hostname \
--is-dba --users --passwords --privileges --roles --dbs --tables \ --is-dba --users --passwords --privileges --roles --dbs --tables \
--columns --schema --count --dump --dump-all --search --comments \ --columns --schema --count --dump --dump-all --search --comments \
-D -T -C -X -U --exclude-sysdbs --where --start --stop \ -D -T -C -X -U --exclude-sysdbs --where --start --stop \
--first --last --sql-query --sql-shell --sql-file --common-tables \ --first --last --sql-query --sql-shell --sql-file --common-tables \
--common-columns --udf-inject --shared-lib --file-read --file-write \ --common-columns --udf-inject --shared-lib --file-read --file-write \
--file-dest --os-cmd --os-shell --os-pwn --os-smbrelay --os-bof \ --file-dest --os-cmd --os-shell --os-pwn --os-smbrelay --os-bof \
--priv-esc --msf-path --tmp-path --reg-read --reg-add --reg-del \ --priv-esc --msf-path --tmp-path --reg-read --reg-add --reg-del \
--reg-key --reg-value --reg-data --reg-type -s -t --batch \ --reg-key --reg-value --reg-data --reg-type -s -t --batch \
--charset --crawl --csv-del --dump-format --eta --flush-session \ --charset --crawl --csv-del --dump-format --eta --flush-session \
--forms --fresh-queries --hex --output-dir --parse-errors \ --forms --fresh-queries --hex --output-dir --parse-errors \
--pivot-column --save --scope --test-filter --update \ --pivot-column --save --scope --test-filter --update \
-z --alert --answers --beep --check-waf --cleanup \ -z --alert --answers --beep --check-waf --cleanup \
--dependencies --disable-coloring --gpage --identify-waf \ --dependencies --disable-coloring --gpage --identify-waf \
--mobile --page-rank --purge-output --smart \ --mobile --page-rank --purge-output --smart \
--sqlmap-shell --wizard' -- "$cur" ) ) --sqlmap-shell --wizard' -- "$cur"))
# this removes any options from the list of completions that have # this removes any options from the list of completions that have
# already been specified somewhere on the command line, as long as # already been specified somewhere on the command line, as long as
# these options can only be used once (in a word, "options", in # these options can only be used once (in a word, "options", in
# opposition to "tests" and "actions", as in the find(1) manpage). # opposition to "tests" and "actions", as in the find(1) manpage).
onlyonce=' -h --help -hh --version -v -d -u --url -l -x -m -r -g -c \ onlyonce=' -h --help -hh --version -v -d -u --url -l -x -m -r -g -c \
--drop-set-cookie --random-agent \ --drop-set-cookie --random-agent \
--ignore-401 \ --ignore-401 \
--ignore-proxy --tor \ --ignore-proxy --tor \
--check-tor \ --check-tor \
--skip-urlencode \ --skip-urlencode \
--force-ssl --hpp -o --predict-output --keep-alive \ --force-ssl --hpp -o --predict-output --keep-alive \
--null-connection -p \ --null-connection -p \
--invalid-bignum --invalid-logical --invalid-string \ --invalid-bignum --invalid-logical --invalid-string \
--no-cast --no-escape \ --no-cast --no-escape \
--text-only \ --text-only \
--titles \ --titles \
-f --fingerprint \ -f --fingerprint \
-a --all -b --banner --current-user --current-db --hostname \ -a --all -b --banner --current-user --current-db --hostname \
--is-dba --users --passwords --privileges --roles --dbs --tables \ --is-dba --users --passwords --privileges --roles --dbs --tables \
--columns --schema --count --dump --dump-all --search --comments \ --columns --schema --count --dump --dump-all --search --comments \
-D -T -C -X -U --exclude-sysdbs \ -D -T -C -X -U --exclude-sysdbs \
--sql-shell --common-tables \ --sql-shell --common-tables \
--common-columns --udf-inject \ --common-columns --udf-inject \
--os-shell --os-pwn --os-smbrelay --os-bof \ --os-shell --os-pwn --os-smbrelay --os-bof \
--priv-esc --reg-read --reg-add --reg-del \ --priv-esc --reg-read --reg-add --reg-del \
-s -t --batch \ -s -t --batch \
--eta --flush-session \ --eta --flush-session \
--forms --fresh-queries --hex --parse-errors \ --forms --fresh-queries --hex --parse-errors \
--save --update \ --save --update \
-z --beep --check-waf --cleanup \ -z --beep --check-waf --cleanup \
--dependencies --disable-coloring --identify-waf \ --dependencies --disable-coloring --identify-waf \
--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 (
[[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] && while read -d ' ' i; do
continue [[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] && continue
# flatten array with spaces on either side, # flatten array with spaces on either side,
# otherwise we cannot grep on word boundaries of # otherwise we cannot grep on word boundaries of
# first and last word # first and last word
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[@]}"
))
# else #else
# _filedir bat #_filedir bat
fi fi
} }
complete -F _sqlmap sqlmap
complete -F _sqlmap sqlmap
fi