如何讓製錶符補全與「rake」一起使用?

如何讓製錶符補全與「rake」一起使用?

當我嘗試使用製表符補全時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

所以我希望按選項卡應該建議可用於 rake 的任務:

$ 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 時會載入製表符補全。安裝應用程式時,您需要重新開啟 shell 或執行下一個命令來載入新的 bash 補全:

. /etc/bash_completion

看起來好像是一個錯誤rake。檢查是否設定了[ -n "${have:-}" ]名為的變數。$have如果前一個呼叫失敗,則此操作將無法運作。將其替換為have rake

have rake && complete -F _rake $filenames rake

相關內容