Answers:
您将需要两个伙伴。一,完成脚本:
_webs() {
local cur prev projdir=/var/www/projects/some/long/path
COMPREPLY=()
cur=$(_get_cword)
prev=${COMP_WORDS[COMP_CWORD-1]}
COMPREPLY=( $( compgen -W '$( command ls "$projdir/$cur*" | sed "s|$projdir/||")' -- '' ) )
}
complete -F _webs webs
_get_cword
取决于要安装的bash-completions软件包。如果没有,请更改以下行:
cur=$(_get_cword)
至:
cur=${COMP_WORDS[$COMP_CWORD]}
二,功能:
webs () {
local projdir=/var/www/projects/some/long/path
cd "$projdir"
do_something_ "$@"
}