python-optcomplete
パッケージ(Debianテストの1.2-11.1 )を使おうとしています:
$ cat /etc/bash_completion.d/optcomplete
_optcomplete()
{
COMPREPLY=( $( \
COMP_LINE=$COMP_LINE COMP_POINT=$COMP_POINT \
COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD \
OPTPARSE_AUTO_COMPLETE=1 $1 ) )
}
$ source /etc/bash_completion.d/optcomplete
$ complete -F _optcomplete optcomplete-test
$ pwd
/tmp/examples
$ ls -l
total 8
-rwxr-xr-x 1 wena wena 3490 Feb 24 23:25 optcomplete-conditional
-rwxr-xr-x 1 wena wena 3521 Feb 24 23:25 optcomplete-simple
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
$ export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/tmp/examples
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/tmp/examples
$ optcomplete-simple -[TAB][TAB]
完了しようとしても何も得られません...この男ほど幸運ではありません。
プロジェクトのWebサイト(ファイル名: "optcomplete-simple")から取得した(切り取った)コードは次のとおりです。
#!/usr/bin/env python
import os
import optparse, optcomplete
def main():
parser = optparse.OptionParser()
parser.add_option('-s', '--simple', action='store_true',
help="Simple really simple option without argument.")
parser.add_option('-o', '--output', action='store',
help="Option that requires an argument.")
opt = parser.add_option('-p', '--script', action='store',
help="Option that takes python scripts args only.")
opt.completer = optcomplete.RegexCompleter('.*\.py')
optcomplete.autocomplete(parser, ['.*\.tar.*'])
opts, args = parser.parse_args()
if __name__ == '__main__':
main()