Skip to content

Instantly share code, notes, and snippets.

@derekschrock
Created September 16, 2017 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derekschrock/53c73ee17948e1be44bd556e7b8e0917 to your computer and use it in GitHub Desktop.
Save derekschrock/53c73ee17948e1be44bd556e7b8e0917 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
if ! [ -d "$1" ] ; then
echo "usage: ${0##*/} dir"
exit
fi
cd "$1"
pkg query "%o" | while read origin; do
keys=$(pkg query "%Ok" "$origin")
if [ -n "$keys" ]; then
dir_package="$(echo $origin | sed 's!/!_!')"
mkdir "$dir_package"
version=$(pkg query "%n-%v" "$origin")
options="$dir_package/options"
> "$options"
cat <<- EOF >> "$options"
# Options for $version
_OPTIONS_READ=$version
_FILE_COMPLETE_OPTIONS_LIST=$(echo $keys)
EOF
pkg query "%Ok %Ov" "$origin" | while read key value; do
unset=$(echo "$value" | sed 's/off/UN/;s/on//')
echo "OPTIONS_FILE_${unset}SET+=${key}"
done >> "$options"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment