Commit 5f12cf41 by Craig Heffner

Added autocomplete install option to install bash autocomplete file

parent 4d65bace
......@@ -236,6 +236,43 @@ class CleanCommand(Command):
pass
class AutoCompleteCommand(Command):
description = "Install bash autocomplete file"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
options = []
autocomplete_file_path = "/etc/bash_completion.d/%s" % MODULE_NAME
auto_complete = '''_binwalk()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="%s"
if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -F _binwalk binwalk'''
(out, err) = subprocess.Popen(["binwalk", "--help"], stdout=subprocess.PIPE).communicate()
for line in out.splitlines():
if b'--' in line:
long_opt = line.split(b'--')[1].split(b'=')[0].split()[0].strip()
options.append('--' + long_opt.decode('utf-8'))
with open(autocomplete_file_path, "w") as fp:
fp.write(auto_complete % ' '.join(options))
class TestCommand(Command):
description = "Run unit-tests"
user_options = []
......@@ -255,10 +292,11 @@ install_data_files = []
for data_dir in ["magic", "config", "plugins", "modules", "core"]:
install_data_files.append("%s%s*" % (data_dir, os.path.sep))
# Create a version.py file which defines the current binwalk version.
# This file is excluded from git in the .gitignore file.
sys.stdout.write("creating %s%s" % (VERSION_FILE, os.linesep))
with open(VERSION_FILE, "w") as fp:
if 'install' in ' '.join(sys.argv) or 'build' in ' '.join(sys.argv):
# Create a version.py file which defines the current binwalk version.
# This file is excluded from git in the .gitignore file.
sys.stdout.write("creating %s%s" % (VERSION_FILE, os.linesep))
with open(VERSION_FILE, "w") as fp:
fp.write("# This file has been auto-generated by setup.py\n")
fp.write('__version__ = "%s"' % MODULE_VERSION)
......@@ -283,4 +321,5 @@ setup(
'uninstall': UninstallCommand,
'idainstall': IDAInstallCommand,
'idauninstall': IDAUnInstallCommand,
'autocomplete' : AutoCompleteCommand,
'test': TestCommand})
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