Skip to content

Instantly share code, notes, and snippets.

@awood
Last active August 29, 2015 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awood/a3a51f7a8bcbcc3b219c to your computer and use it in GitHub Desktop.
Save awood/a3a51f7a8bcbcc3b219c to your computer and use it in GitHub Desktop.
Zsh function to run repoquery against mock configs

Drop mock-repoquery in the ~/.zfunc directory and add the following to your ~/.zshrc:

fpath=( ~/.zfunc "${fpath[@]}" )
autoload -Uz mock-repoquery
#! /bin/zsh
mock-repoquery() {
local profile="$1"
[ -f "$profile" ] || profile="/etc/mock/${1}.cfg"
# Take all baseurls in a file and make them into an array
# See Parameter Expansion Flags section of the zshexpn man page and
# http://unix.stackexchange.com/a/29748
local repo_urls
repo_urls=("${(@f)$(sed -n -r 's/.*baseurl=(.*)(\\n|$)/\1/p' $profile | cut -d'\' -f1)}")
local repo_args
repo_args=()
for ((i=1; i <= ${#repo_urls}; i++)); do
repo_args+="--repofrompath=r${i},$repo_urls[i]"
repo_args+="--repoid=r${i}"
done
repoquery "${repo_args[@]}" "$@[2,-1]"
}
mock-repoquery "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment