2 # Programmable bash completion for hashcat
3 # this script was tested under ubuntu, please verify if on your
4 # distro /etc/bash_completion.d/ exists (otherwise it won't work)
6 COMPGENSCRIPT=/etc/bash_completion
7 COMPGENFOLDER=${COMPGENSCRIPT}.d
8 COMPGENTARGET=${COMPGENFOLDER}/hashcat.sh
10 ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12 #############################################################################
16 if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
31 # load the completion into current shell
33 if [ "${is_child}" -eq 1 ]; then
35 if [ "${parent_sourced}" -eq 0 ]; then
43 if [ "${was_sourced}" -eq 0 ]; then
45 source "${COMPGENTARGET}"
58 if [ "${was_sourced}" -eq 0 ]; then
71 if [ "$(id -g)" -eq 0 ]; then
83 #############################################################################
88 ROOT_PARENT="$(cd ${ROOT}/.. && pwd)"
90 # Check (install) permissions
97 echo "Warning: root permissions are required to install the tab completion script into the protected '${COMPGENFOLDER}' folder"
99 sudo ${BASH_SOURCE[0]} ${was_sourced}
103 if [ "${ret}" -eq 0 ]; then
122 if [ -f "${COMPGENFOLDER}" ]
125 echo "The bash completion script file (${COMPGENSCRIPT}) could not be found"
126 echo "Please make sure that the distro 'bash-completion' package is installed (apt-get install it otherwise). EXIT"
132 if [ -d "${COMPGENFOLDER}" ]; then
134 # remove the old version of hashcat64.sh (was renamed to just hashcat.sh)
136 rm -f "${COMPGENTARGET}"/hashcat64.sh
138 # copy the script to target folder
140 cp ${ROOT}/hashcat.sh "${COMPGENTARGET}"
142 # adjust paths to the main binaries of hashcat
144 sed -ri "s!^(ROOT=).*!\1\"${ROOT_PARENT}\"!" "${COMPGENTARGET}"
147 # add the compgen to bashrc if not already there
149 if ! egrep -q "^[^#]*\. *${COMPGENSCRIPT}" "${BASHRC}"; then
151 cat >> "${BASHRC}" << EOF
153 if [ -f "${COMPGENSCRIPT}" ]; then
163 if source_completion; then
165 echo "Bash completion scripts for hashcat were successfully installed, but since you didn't 'source' this file, you need to run:"
166 echo "source ${COMPGENTARGET} # or source ${BASHRC}"
168 echo "in order to be able to use the tab completion within the current shell."
174 echo "The compgen script folder (${COMPGENFOLDER}) could NOT be found. EXIT"