跟我一起写shell补全脚本(Bash篇) - SegmentFault
在上一篇里我们定下了给pandoc
写补全脚本的计划:
- 支持主选项(General options)
- 支持子选项(Reader options/General writer options)
- 支持给选项提供参数值来源。比如在敲
pandoc -f
之后,能够补全FORMAT
的内容。
支持主选项
先列出实现了第一阶段目标的程序:
# 以pandoc的名字保存下面的程序 _pandoc() { local pre cur opts COMPREPLY=() #pre="$3" #cur="$2" pre=${COMP_WORDS[COMP_CWORD-1]} cur=${COMP_WORDS[COMP_CWORD]} opts="-f -r -t -w -o --output -v --version -h --help" case "$cur" in -* ) COMPREPLY=( $( compgen -W "$opts" -- $cur ) ) esac } complete -F _pandoc -A file pandoc
Read full article from 跟我一起写shell补全脚本(Bash篇) - SegmentFault
No comments:
Post a Comment