【发布时间】:2016-07-09 20:02:03
【问题描述】:
我正在学习 bash 补全。我只能列出当前目录的内容。这是我的代码:
_foo()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="push pull"
OUTPUT=" $(ls) "
case "${prev}" in
push)
COMPREPLY=( $(compgen -W "--in --out" -- ${cur}) )
return 0
;;
--in)
COMPREPLY=( $(compgen -W "$OUTPUT" -- ${cur}) )
return 0
;;
esac
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
}
complete -F _foo foo
它的输出是:
$ foo push --in[TAB]
file1.txt file2.txt foo ;; content of pwd
但是当我这样做时:
$ foo push --in ~[TAB]
它不工作。 所以我想知道如何在不同的目录中完成 bash(不仅在 pwd 中)?谢谢。
【问题讨论】:
-
哦,它们实际上不在脚本中。这些只是因为 Vim 编辑器。我从那里复制了这个脚本,所以也复制了行号。
标签: bash autocomplete bash-completion