From b4f9d6e0b325c71c62b19825b42758e8110ee871 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Sun, 13 Mar 2011 16:39:06 +0100 Subject: Enhanced the open_ebuild function --- .zsh/zshfunctions | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to '.zsh/zshfunctions') diff --git a/.zsh/zshfunctions b/.zsh/zshfunctions index 70ce3b5..92f88f2 100644 --- a/.zsh/zshfunctions +++ b/.zsh/zshfunctions @@ -14,14 +14,37 @@ _cdu () # Open the ebuild with a specified command open_ebuild () { - local ebuild=$(equery --debug w $2 2> /dev/null) - - if [[ -z $ebuild ]]; then - echo "Trying masked packages too..." - ebuild=$(equery --debug w -m $2 2> /dev/null) + local ebuild sel + local -a elist + + ebuild="$(equery w $2 2>&1 )" + if [[ $? -ne 0 ]]; then + if [[ $ebuild == *"Ambiguous"* ]]; then + elist=(${(f)ebuild}) + + # remove the first line + shift elist + + echo "Ambiguous package name '$2' -- choose from: " + cat -n <<< ${(F)elist} + read "sel?Selection: " + + if [[ -z $elist[$sel] ]]; then + echo "Invalid choice." + return 1 + else + # the "=" is needed to strip the leading spaces and the quotes + open_ebuild $1 ${=elist[$sel]} + return $? + fi + + elif [[ $ebuild == *"No packages matching"* ]]; then + echo "Trying masked packages too..." + ebuild=$(equery w -m $2 2>&1) + fi fi - if [[ -n $ebuild ]]; then + if [[ $? -eq 0 ]]; then $1 $ebuild else echo "No ebuild found" -- cgit v1.2.3-54-g00ecf