
でタブ補完を使用しようとすると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
$
シェルで明示的に実行しても. /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
タブ補完はシェルを開くときに読み込まれます。アプリケーションをインストールするときは、シェルを再度開くか、次のコマンドを実行して新しい bash 補完を読み込む必要があります。
. /etc/bash_completion
どうやらバグrake
.では、[ -n "${have:-}" ]
指定された変数$have
が設定されているかどうかを確認します。前の have 呼び出しが失敗した場合は機能しません。次のコードに置き換えますhave rake
。
have rake && complete -F _rake $filenames rake