Commit a122a09a by devttys0

Removed binwalk completion file.

parent 6a97595f
# Bash auto-completion file for binwalk
_binwalk()
{
local cur prev opts long_opts short_opts file_opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# Long and short options are dynamically generated by setup.py
long_opts="%%LONG_OPTS%%"
short_opts="%%SHORT_OPTS%%"
file_opts="--file --extract --magic"
opts="${long_opts} ${short_opts}"
# If this is a long option, then tab complete a list of matching long options
if [[ ${cur} == --* ]]
then
COMPREPLY=( $(compgen -W "${long_opts}" -- ${cur}) )
# Else, if this is any other option, tab complete it from then entire list of valid options
elif [[ ${cur} == -* ]]
then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
# Finally, if this is not an option at all, tab complete a list of files
else
COMPREPLY=( $(compgen -f ${cur}) )
fi
# If there is only one matching option, and if it is a long option, then don't put a space after the equals sign.
if [ "$(echo "$COMPREPLY" | wc -w)" == "1" ] && [ "$(echo "$COMPREPLY" | grep -e '=$')" != "" ]
then
compopt -o nospace;
# Else, if there are no matching options, check to see if the previous option is a long option that takes a file path argument
elif [ "$COMPREPLY" == "" ]
then
for file_opt in ${file_opts}
do
if [ "${prev}" == "${file_opt}" ]
then
# If the previous option does take a file path argument, tab complete a list of files
COMPREPLY=( $(compgen -f "") )
break
fi
done
fi
return 0
}
complete -F _binwalk binwalk
...@@ -133,47 +133,3 @@ setup( name = "binwalk", ...@@ -133,47 +133,3 @@ setup( name = "binwalk",
scripts = ["bin/binwalk"], scripts = ["bin/binwalk"],
) )
# If the bash auto-completion directory exists, generate an auto-completion file
bash_completion_dir = os.path.join('/', 'etc', 'bash_completion.d')
if os.path.exists(bash_completion_dir):
import binwalk.cmdopts
print("Installing bash auto-completion file")
long_opts_key = '%%LONG_OPTS%%'
short_opts_key = '%%SHORT_OPTS%%'
file_opts_key = '%%FILE_OPTS%%'
file_name_in = 'binwalk.completion'
file_name_out = os.path.join(bash_completion_dir, 'binwalk')
long_opts = []
short_opts = []
file_opts = ['--file=', '--extract=', '--magic=']
for opt in binwalk.cmdopts.short_options:
if opt != ':':
short_opts.append('-' + opt)
for opt in binwalk.cmdopts.long_options:
long_opts.append('--' + opt)
try:
with open(file_name_in) as fd_in:
with open(file_name_out, 'w') as fd_out:
for line in fd_in.readlines():
if long_opts_key in line:
line = line.replace(long_opts_key, ' '.join(long_opts))
elif short_opts_key in line:
line = line.replace(short_opts_key, ' '.join(short_opts))
elif file_opts_key in line:
line = line.replace(file_opts_key, ' '.join(file_opts))
fd_out.write(line)
except Exception as e:
print("WARNING: Failed to install auto-completion file: %s" % e)
try:
os.unlink(file_name_out)
except:
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment