holehe命令行补全:Bash与Zsh自动补全功能的配置

holehe命令行补全:Bash与Zsh自动补全功能的配置

【免费下载链接】holehe holehe allows you to check if the mail is used on different sites like twitter, instagram and will retrieve information on sites with the forgotten password function. 【免费下载链接】holehe 项目地址: https://gitcode.com/gh_mirrors/ho/holehe

为什么需要命令行补全?

在使用holehe进行电子邮件账户查询时,你是否经常忘记具体的命令参数?例如--only-used--no-color选项的拼写,或者在输入多个邮箱地址时希望获得自动提示?命令行补全(Command Line Completion)功能可以通过按下Tab键自动补全命令、参数和文件名,将操作效率提升40%以上,同时减少输入错误。

本文将详细介绍如何为holehe配置Bash和Zsh的自动补全功能,让你的OSINT(开源情报)调查工作更加流畅高效。

补全原理与实现思路

基本工作流程

命令行补全功能通过分析程序的参数定义,在用户输入时动态生成可能的补全选项。对于holehe而言,其参数定义位于holehe/core.py文件的180-195行,使用Python标准库argparse模块定义了所有命令行选项:

parser= ArgumentParser(description=f"holehe v{__version__}")
parser.add_argument("email", nargs='+', metavar='EMAIL', help="Target Email")
parser.add_argument("--only-used", default=False, action="store_true", dest="onlyused", help="Displays only the sites used by the target email address.")
parser.add_argument("--no-color", default=False, action="store_true", dest="nocolor", help="Don't color terminal output")
parser.add_argument("--no-clear", default=False, action="store_true", dest="noclear", help="Do not clear the terminal to display the results")
parser.add_argument("-NP","--no-password-recovery", default=False, action="store_true", dest="nopasswordrecovery", help="Do not try password recovery on the websites")
parser.add_argument("-C","--csv", default=False, action="store_true", dest="csvoutput", help="Create a CSV with the results")
parser.add_argument("-T","--timeout", type=int , default=10, required=False, dest="timeout", help="Set max timeout value (default 10)")

补全脚本的核心任务就是解析这些定义,并将其转换为shell能够理解的补全规则。

支持的补全类型

根据holehe的参数特点,我们需要实现以下补全场景:

  1. 选项补全:当输入--后,补全所有可用选项(如--only-used--no-color
  2. 短选项补全:当输入-后,补全所有短选项(如-NP-C
  3. 参数值补全:对于--timeout选项,补全数字类型
  4. 邮箱补全:在输入邮箱地址时,提供常见邮箱域名补全(如@gmail.com@outlook.com

Bash补全配置

安装补全脚本

  1. 创建Bash补全文件

    sudo tee /etc/bash_completion.d/holehe << 'EOF'
    #!/bin/bash
    
    _holehe_completions() {
        local cur prev opts
        COMPREPLY=()
        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"
    
        # 基础选项列表,从holehe/core.py中提取
        opts="--only-used --no-color --no-clear -NP --no-password-recovery -C --csv -T --timeout"
    
        # 短选项补全
        if [[ ${cur} == -* ]]; then
            COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
            return 0
        fi
    
        # --timeout参数补全数字
        if [[ ${prev} == "--timeout" || ${prev} == "-T" ]]; then
            COMPREPLY=( $(compgen -W "5 10 15 20" -- ${cur}) )
            return 0
        fi
    
        # 邮箱地址补全
        if [[ ${cur} == *@* ]]; then
            local domains="gmail.com outlook.com yahoo.com protonmail.com"
            COMPREPLY=( $(compgen -W "${domains}" -- ${cur#*@}) )
            # 添加@前缀
            COMPREPLY=( "${COMPREPLY[@]/#/${cur%@*}@}" )
            return 0
        fi
    }
    
    complete -F _holehe_completions holehe
    EOF
    
  2. 使配置生效

    source /etc/bash_completion.d/holehe
    # 永久生效(添加到bash配置文件)
    echo "source /etc/bash_completion.d/holehe" >> ~/.bashrc
    

使用效果演示

输入以下命令并按下Tab键:

holehe test@gm[Tab]  # 自动补全为test@gmail.com
holehe --on[Tab]     # 自动补全为--only-used
holehe -T 1[Tab]     # 自动补全为10(默认超时值)

Zsh补全配置

安装补全脚本

  1. 创建Zsh补全文件

    mkdir -p ~/.zsh/completions
    tee ~/.zsh/completions/_holehe << 'EOF'
    #compdef holehe
    
    local arguments
    
    arguments=(
      '1:email address:_mail_addresses'
      '--only-used[Displays only the sites used by the target email address]'
      '--no-color[Don\'t color terminal output]'
      '--no-clear[Do not clear the terminal to display the results]'
      '-NP[Do not try password recovery on the websites]'
      '--no-password-recovery[Do not try password recovery on the websites]'
      '-C[Create a CSV with the results]'
      '--csv[Create a CSV with the results]'
      '-T[Set max timeout value]:timeout:(5 10 15 20)'
      '--timeout[Set max timeout value]:timeout:(5 10 15 20)'
    )
    
    _arguments -s $arguments
    EOF
    
  2. 配置Zsh加载补全文件

    echo 'fpath=($HOME/.zsh/completions $fpath)' >> ~/.zshrc
    echo 'autoload -Uz compinit && compinit' >> ~/.zshrc
    
  3. 使配置生效

    source ~/.zshrc
    

高级补全特性

Zsh补全相比Bash提供了更多高级功能:

  1. 参数类型提示:当输入--timeout后,会显示(5 10 15 20)作为建议值
  2. 描述信息显示:使用Ctrl+I可以查看每个选项的帮助描述
  3. 邮箱验证:集成了Zsh内置的_mail_addresses函数,提供标准邮箱格式验证

验证与故障排除

验证补全功能

执行以下命令验证补全是否正常工作:

# 验证基础选项补全
holehe --[Tab]  # 应显示所有可用选项

# 验证参数补全
holehe -T [Tab]  # 应显示5 10 15 20

# 验证邮箱补全
holehe user@[Tab]  # 应显示常见邮箱域名

常见问题解决

  1. 补全不生效

    • 检查补全文件权限:ls -l /etc/bash_completion.d/holehe(Bash)或~/.zsh/completions/_holehe(Zsh)
    • 确认已重新加载配置文件:source ~/.bashrcsource ~/.zshrc
    • 对于Zsh,执行compinit重新生成补全缓存
  2. 补全选项不完整

    如果holehe更新了新的命令行选项,你需要同步更新补全脚本中的opts变量。可以通过以下命令快速提取最新参数列表:

    grep "add_argument" holehe/core.py | grep -oE "--[a-z-]+|-[A-Z]" | sort -u
    

自动化维护与更新

为了确保补全脚本与holehe的最新版本保持同步,你可以创建一个简单的更新脚本:

tee ~/update-holehe-completion.sh << 'EOF'
#!/bin/bash

# 提取最新参数
opts=$(grep "add_argument" /path/to/holehe/core.py | grep -oE "--[a-z-]+|-[A-Z]" | sort -u | tr '\n' ' ')

# 更新Bash补全文件
sed -i "s/opts=\".*\"/opts=\"${opts}\"/" /etc/bash_completion.d/holehe

# 更新Zsh补全文件
# (类似操作,这里省略)

echo "补全脚本已更新"
EOF

chmod +x ~/update-holehe-completion.sh

建议在每次更新holehe后执行此脚本,或者将其添加到crontab定期运行。

总结

通过本文介绍的方法,你已经成功为holehe配置了Bash或Zsh的自动补全功能。这将显著提升你在进行电子邮件调查时的工作效率,减少记忆负担和输入错误。

补全脚本的核心价值在于:

  • 基于holehe/core.py的官方参数定义,确保补全选项的准确性
  • 针对holehe的使用场景优化,提供邮箱域名等特定补全
  • 兼容Bash和Zsh两种主流shell,满足不同用户习惯

希望这个配置指南能帮助你更高效地使用holehe进行OSINT调查工作!

【免费下载链接】holehe holehe allows you to check if the mail is used on different sites like twitter, instagram and will retrieve information on sites with the forgotten password function. 【免费下载链接】holehe 项目地址: https://gitcode.com/gh_mirrors/ho/holehe

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值