Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/homebrew: support homebrew/cask (wip) #128

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 41 additions & 5 deletions lib/homebrew.sh
Expand Up @@ -17,17 +17,52 @@ _homebrew_init() {
:
}

# NOTE: brew can call cask if necessary.
# NOTE: However, it always returns 1 when cask is used.
# NOTE: homebrew/cask complete
homebrew_Qi() {
brew info "$@"
}

# homebrew_QL may _not_implemented
# NOTE: homebrew features are inconsistent. Without any arguments
# NOTE: it prints the list of all installed packages. Otherwise
# NOTE: it prints the list of files of a package.
# NOTE: homebrew/cask almost complete
homebrew_Ql() {
brew list "$@"
if [[ -z "${@:-}" ]]; then
_not_implemented
return
fi

2>&1 brew list "$@" \
| awk 'BEGIN { idx = 0; }
{ lines[idx] = $0; idx += 1; if ($0 ~ /Found a cask named/) { idx = 0; exit(126); } }
END { for (j = 0; j < idx; j ++) { print(lines[j]); } }'
ret=( ${PIPESTATUS[*]} )
if [[ "${ret[1]}" != 126 ]]; then
return "${ret[0]}"
fi

echo >&2 ":: Trying now with homebrew/cask"
brew cask info "$@" 2>&1 \
| grep -oEe "^(/.+Caskroom/.+) \([0-9]+ files, " \
| sed -E -e 's/ \([0-9]+ files, //' \
| while read -r dir; do
find "$dir" -type f
done
}

# FIXME: This function doesn't work well.
# FIXME: THis function doesn't support homebrew/cask
homebrew_Qo() {
local pkg prefix cellar

if [[ -z "${@:-}" ]]; then
_not_implemented
return
fi

# FIXME: What happens if the file is not exectutable?
cd "$(dirname -- "$(which "$@")")" || return
pkg="$(pwd -P)/$(basename -- "$@")"
Expand All @@ -44,24 +79,25 @@ homebrew_Qo() {
}

homebrew_Qc() {
brew log "$@"
brew log "${@:-}"
}

homebrew_Qu() {
brew outdated | grep "$@"
brew outdated | grep "${@:-.}"
}

homebrew_Qs() {
brew list | grep "$@"
brew list | grep "${@:-.}"
}

# homebrew_Q may _not_implemented
homebrew_Q() {
if [[ "$_TOPT" == "" ]]; then
if [[ "$*" == "" ]]; then
brew list
brew cask list
else
brew list | grep "$@"
{ brew list ; brew cask list ; } | grep "$@"
fi
else
_not_implemented
Expand Down