Closed zijuexiansheng closed 5 years ago
Yeah that function is really not ideal. It's certainly unnecessary to involve external utility calls just to check file mtimes. Off the top of my head i would suggest something like this:
__brew_completion_caching_policy() {
local -a tmp
# Invalidate if cache file is >2 weeks old
tmp=( $1(mw-2N) )
(( $#tmp )) || return 0
# Otherwise, invalidate if latest tap index file is newer than cache file
tmp=( ${HOMEBREW_REPOSITORY:-/usr/local/Homebrew}/Library/Taps/*/*/.git/index(om[1]N) )
[[ $tmp -nt $1 ]]
}
On a related note, the command helper functions shouldn't keep forcibly setting a cache-policy
like they're doing. The main _brew
function should set it once and only if it's not already set. (The reason the caching system uses the zstyle
mechanism at all is to allow the user to customise how it works. Forcibly overriding it every time defeats that purpose.)
I just noticed this ticket at the top of the list when i was going to search for another issue, so i don't have a PR prepared, but if nobody else beats me to it maybe i can do something later.
This issue is caused by the
date -r "$1" +s
command in the__brew_completion_caching_policy()
function in the_brew
file. By the detailed output I posted above, the-r
parameter should be followed by "seconds" rather than a file name. So I propose to usestat -f "%m" "$1"
instead. One can define the following function
This seems reasonable. Can you (or @okdana) open a PR? Thanks!
Please note that we will close your issue without comment if you delete, do not read or do not fill out the issue checklist below and provide ALL the requested information. If you repeatedly fail to use the issue template, we will block you from ever submitting issues to Homebrew again.
brew
command and reproduced the problem with multiple formulae? If it's a problem with a single, official formula (not cask) please file this issue at Homebrew/homebrew-core: https://github.com/Homebrew/homebrew-core/issues/new/choose. If it's abrew cask
problem please file this issue at https://github.com/Homebrew/homebrew-cask/issues/new/choose. If it's a tap (e.g. Homebrew/homebrew-php) problem please file this issue at the tap.brew update
and can still reproduce the problem?brew doctor
, fixed all issues and can still reproduce the problem?brew config
andbrew doctor
and included their output with your issue?What you were trying to do (and why)
I'm trying to use the autocompletion of homebrew and got some error output.
What happened (include command output)
When I hit the tab to auto complete, I constantly get the following output.
Command output
Issue description and proposed solution
This error will not appear in Linux system (or maybe newer Mac OS). My system is Mac OS 10.10.5 and the
date
command is different than the one in the Linux system.This issue is caused by the
date -r "$1" +s
command in the__brew_completion_caching_policy()
function in the_brew
file. By the detailed output I posted above, the-r
parameter should be followed by "seconds" rather than a file name. So I propose to usestat -f "%m" "$1"
instead. One can define the following functionand replace the
__brew_completion_caching_policy()
by