#autoload # Usage: # _gentoo_repos -> returns the list of all repos # _gentoo_repos -m -> returns the main repo # _gentoo_repos -o -> returns the list of non-main repos _gentoo_repos() { local main_repo main_repo_path overlay overlay_paths if [[ -e /usr/share/portage/config/repos.conf ]]; then main_repo=$(_repos_conf DEFAULT main-repo) main_repo_path=$(_repos_conf ${main_repo} location) for overlay in $(_repos_conf -l); do overlay_paths+=($(_repos_conf ${overlay} location)) done source /etc/make.conf 2>/dev/null source /etc/portage/make.conf 2>/dev/null overlay_paths+=(${(@)PORTDIR_OVERLAY}) else source /usr/share/portage/config/make.globals 2>/dev/null source /etc/make.conf 2>/dev/null source /etc/portage/make.conf 2>/dev/null main_repo_path="${PORTDIR}" overlay_paths=(${(@)PORTDIR_OVERLAY}) fi if [[ $1 == "-m" ]]; then echo "${main_repo_path}" elif [[ $1 == "-o" ]]; then echo "${(@u)overlay_paths}" else echo "${main_repo_path} ${(@u)overlay_paths}" fi } _repos_conf() { local v file insection section arr for file in /usr/share/portage/config/repos.conf \ /etc/portage/repos.conf \ /etc/portage/repos.conf/*.conf; do [[ -f ${file} ]] || continue insection=0 declare -A arr IFS='= ' while read -r name value; do [[ -z ${name} || ${name} == '#'* ]] && continue if [[ (${name} == '['*']') && (-z ${value}) ]]; then value=${name//(\]|\[)} name="section" fi arr[${name}]=${value} if [[ ${insection} == 1 && ${name} == "section" ]]; then break elif [[ ${name} == "section" ]]; then [[ ${value} == ${1} ]] && insection=1 secname+=(${value}) elif [[ ${insection} == 1 ]]; then if [[ ${name} == ${2} ]]; then v=${value} fi fi continue done < ${file} done if [[ ${1} == "-l" ]]; then echo "${(@)secname}" else echo "${v}" fi } _gentoo_repos "$@" # vim: set et sw=2 ts=2 ft=zsh: