diff options
Diffstat (limited to '')
-rw-r--r-- | .zsh/zshfunctions | 35 |
1 files changed, 29 insertions, 6 deletions
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" |