Skip to content

Latest commit

 

History

History
38 lines (30 loc) · 849 Bytes

0035_bash_complete.md

File metadata and controls

38 lines (30 loc) · 849 Bytes

bash complete

参考文档

git补全原理

  • bash启动的时候,会加载/etc/bash_completion.d中的文件,并执行. /etc/bash_completion
  • ls /etc/bash_completion.d
    git-prompt
    

示例

  • cat dothis
    #/usr/bin/env bash
    
    _dothis_completions()
    {
      COMPREPLY+=("now")
      COMPREPLY+=("tomorrow")
      COMPREPLY+=("never")
    }
    
    complete -F _dothis_completions dothis
    
  • sudo cp dothis /etc/bash_completion.d/
  • sudo cp dothis /bin
  • bash
  • dothis <tab><tab>
    never     now       tomorrow