当我尝试使用制表符完成功能时rake
,仅建议文件:
$ rails test-app | grep -v create; cd test-app
$ rake <TAB><TAB>
app/ db/ lib/ public/ README test/ vendor/
config/ doc/ log/ Rakefile script/ tmp/
该软件包rake-0.8.7-2
包含一个 Bash 完成配置文件,
$ debsums -e rake
/etc/bash_completion.d/rake OK
因此我希望按下 Tab 键可以建议可用的任务:
$ rake --tasks
(in ~/sandbox/test-app)
rake db:abort_if_pending_migrations # Raises an error if there are pending migrations
rake db:charset # Retrieves the charset for the current environment's database
rake db:collation # Retrieves the collation for the current environment's database
rake db:create # Create the database defined in config/database.yml for the current RAIL...
rake db:create:all # Create all the local databases defined in config/database.yml
rake db:drop # Drops the database for the current RAILS_ENV
...
我究竟做错了什么?
重新安装 rake 并重启电脑后,问题仍然存在。我的~/.bashrc
文件包含:
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
但完成rake
似乎没有被注册:
$ complete | grep rake
$
在 shell 中明确运行. /etc/bash_completion
并不能解决问题,但运行以下命令确实可以rake
暂时启用完成:
$ grep complete /etc/bash_completion.d/rake
[ -n "${have:-}" ] && complete -F _rake $filenames rake
$ complete -F _rake rake
$ rake <TAB><TAB>
db:abort_if_pending_migrations db:version rails:update
db:charset doc:app rails:update:application_controller
db:collation doc:clobber_app rails:update:configs
db:create doc:clobber_plugins rails:update:generate_dispatchers
db:create:all doc:clobber_rails rails:update:javascripts
db:drop doc:guides rails:update:scripts
...
答案1
打开 shell 时会加载 Tab 补全。安装应用程序时,您需要重新打开 shell 或运行下一个命令来加载新的 bash 补全:
. /etc/bash_completion
看起来是一个错误在rake
.中[ -n "${have:-}" ]
检查是否设置了名为的变量$have
。如果之前的 have 调用失败,这将不起作用。将其替换为have rake
:
have rake && complete -F _rake $filenames rake