diff --git a/setup.py b/setup.py
index cd18397..9fde36f 100755
--- a/setup.py
+++ b/setup.py
@@ -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,12 +292,13 @@ 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:
-    fp.write("# This file has been auto-generated by setup.py\n")
-    fp.write('__version__ = "%s"' % MODULE_VERSION)
+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)
 
 # Install the module, script, and support files
 setup(
@@ -283,4 +321,5 @@ setup(
         'uninstall': UninstallCommand,
         'idainstall': IDAInstallCommand,
         'idauninstall': IDAUnInstallCommand,
+        'autocomplete' : AutoCompleteCommand,
         'test': TestCommand})