--- john.bash_completion.orig 2012-06-01 23:42:24.610766224 +0000 +++ john.bash_completion 2012-06-03 14:45:52.157724239 +0000 @@ -55,11 +55,11 @@ # If ${cur#*=} is not empty, completion works even in the middle # of the command line # This is annoying if I want to complete --rules= in -# ./john --rules= --config=test.conf +# ./john --rules= --config=test.conf # # FIXME: If there is a word -- preceding the current word -# which is to be completed, it cannot be an option, so file names -# should be used for completion. +# which is to be completed, it cannot be an option, so file names +# should be used for completion. # # FIXME: Should completion for --make-charset really list existing .chr files? # @@ -68,13 +68,13 @@ # # TODO: # --wordlist=~user/filename or --wordlist=~/dir/file doesn't work, -# but pressing [tab] expands this to something useful -# Where to fix this? In john? Some bash config option? +# but pressing [tab] expands this to something useful +# Where to fix this? In john? Some bash config option? # # --external should not use all names of [List.External:..-.] sections, but -# just sections without a generate() function, if --wordlist, --incremental or --single -# is present on the command line; and just those with a generate() function, -# if none of these options is used - WHAT IF the user adds a --wordlist option later? +# just sections without a generate() function, if --wordlist, --incremental or --single +# is present on the command line; and just those with a generate() function, +# if none of these options is used - WHAT IF the user adds a --wordlist option later? # # Should expanding an abbreviated option to its long form also be done by john itself # (requires new john option)? @@ -89,6 +89,7 @@ _john() { local first cur options valopts compreplya compreplyb encodings formats subformats list hidden dir cmd i ver ver1 ver2 ver3 prev words + COMPREPLY=() if [[ "${COMP_WORDBREAKS}" == *:* ]] ; then @@ -101,6 +102,9 @@ _john() # export COMP_WORDBREAKS="${COMP_WORDBREAKS//:}" # just replace : with = in -opt:val if [[ "${cur}" == -*:* ]] ; then + if [[ "${cur}" == -*[:=]*[:=]* ]] ; then + return 0 + fi cur="${cur//:/=}" COMPREPLY=( $(compgen -W "${cur}" -- ${cur}) ) compopt -o nospace @@ -134,21 +138,25 @@ _john() # with --list=hidden-options # Currently, all hidden options do have mandatory values (--option=value), this makes # addition of these easier - hidden="" hidden=`${first} --list=hidden-options 2>/dev/null|sed 's#^\(--[a-z-]*=\?\).*$#\1#'` case "${cur}" in - -?(-)fo?(r|rm|rma|rmat)+(=|:)dynamic*) + -?(-)f?(o|or|orm|orma|ormat)+(=|:)dynamic*) if [[ "${options}" == *--subformat* ]] ; then + if [[ "${cur#*f}" == [=:]* || "${cur#*f}" == o[=:]* || "${cur#*f}" == or[=:]* ]] ; then + if [[ `echo "${valopts}"|grep -c "^-*${cur%[=:]*}"` -ne 1 ]] ; then + return 0 + fi + fi subformats=`${first} --subformat=LIST|sed 's#^\(User\)\?Format = \(dynamic_[0-9]*\).*$#\2#'` cur=${cur#*[=:]} COMPREPLY=( $(compgen -W "${subformats}" -- ${cur}) ) fi return 0 ;; - -?(-)fo?(r|rm|rma|rmat)+(=|:)dy?(n|na|nam|nami)) + -?(-)f?(o|or|orm|orma|ormat)+(=|:)dy?(n|na|nam|nami)) if [[ "${options}" == *--subformat* ]] ; then - if [[ "${cur#*f}" == o[=:]* || "${cur#*f}" == or[=:]* ]] ; then + if [[ "${cur#*f}" == [=:]* || "${cur#*f}" == o[=:]* || "${cur#*f}" == or[=:]* ]] ; then if [[ `echo "${valopts}"|grep -c "^-*${cur%[=:]*}"` -ne 1 ]] ; then return 0 fi @@ -159,8 +167,9 @@ _john() fi return 0 ;; - -?(-)fo?(r|rm|rma|rmat)+(=|:)*) - if [[ "${cur#*f}" == o[=:]* || "${cur#*f}" == or[=:]* ]] ; then + -?(-)f?(o|or|orm|orma|ormat)+(=|:)*) + + if [[ "${cur#*f}" == [=:]* || "${cur#*f}" == o[=:]* || "${cur#*f}" == or[=:]* ]] ; then if [[ `echo "${valopts}"|grep -c "^-*${cur%[=:]*}"` -ne 1 ]] ; then return 0 fi @@ -255,7 +264,12 @@ _john() fi return 0 ;; - -?(-)ex?(t|te|ter|tern|terna|ternal)+(=|:)*) + -?(-)e?(x|xt|xte|xter|xtern|xterna|xternal)+(=|:)*) + if [[ "${cur}" == -e[=:]* || "${cur}" == --e[=:]* ]] ; then + if [[ `echo "${valopts}"|grep -c "^-*${cur%[=:]*}"` -ne 1 ]] ; then + return 0 + fi + fi cmd=`echo ${COMP_LINE}|sed "s# ${cur}# --list=externals #"` list=`${cmd} 2>/dev/null` if [[ $? -ne 0 ]] ; then @@ -329,7 +343,12 @@ _john() fi return 0 ;; - -?(-)mak?(e|e-|e-c|e-ch|e-cha|e-char|e-chars|e-charse|e-charset)+(=|:)*) + -?(-)m?(a|ak|ake|ake-|ake-c|ake-ch|ake-cha|ake-char|ake-chars|ake-charse|ake-charset)+(=|:)*) + if [[ "${cur#*[=:]}" != *e* ]] ; then + if [[ `echo "${valopts}"|grep -c "^-*${cur%[=:]*}"` -ne 1 ]] ; then + return 0 + fi + fi cur=${cur#*[=:]} #redirect stderr just in case __expand_tilde_by_ref #doesn't exist everywhere @@ -361,7 +380,12 @@ _john() ;; --show) if [[ "${valopts}" == *${cur}* ]] ; then - COMPREPLY=( $(compgen -W "--show --show=LEFT" -- ${cur}) ) + if [[ "_${__john_completion}" == "_2" ]] ; then + COMPREPLY=( $(compgen -W "${cur}=" -- ${cur}) ) + compopt -o nospace + else + COMPREPLY=( $(compgen -W "--show --show=LEFT" -- ${cur}) ) + fi else COMPREPLY=( $(compgen -W "--show" -- ${cur}) ) fi @@ -531,8 +555,10 @@ complete -F _john john _unique() { local first cur usage options valopts compreplya compreplyb - COMPREPLY=() - _get_comp_words_by_ref -n = cur + + COMPREPLY=() + + _get_comp_words_by_ref -n = cur # we need to make sure we run the correct program, not some other program # called unique which is located somewhere in $PATH @@ -549,7 +575,7 @@ _unique() return 0 ;; _-inp=*|_-ex_file=*|_-ex_file_only=*) - cur=${cur#*=} + cur=${cur#*=} __expand_tilde_by_ref cur 2>/dev/null _filedir return 0