Skip to content

Instantly share code, notes, and snippets.

@trq
Last active December 19, 2015 20:59
Show Gist options
  • Save trq/6017160 to your computer and use it in GitHub Desktop.
Save trq/6017160 to your computer and use it in GitHub Desktop.
# I have a command "opm" which takes, for example argument like:
# opm lfs-base/gcc-4.2 configure
#
# The first argument represents a build script in the format of <category>/<package>-<version>
#
# These build scripts are stored within /var/opm/opms/ in a structure similar to:
# .
# |-- lfs-base
# | |-- autoconf
# | | |-- 2.69.opm
# | | `-- base.opm
# | |-- automake
# | | |-- 1.13.1.opm
# | | `-- base.opm
# | |-- bash
# | | |-- 4.2.opm
# | | `-- base.opm
#
# I would love this directory / filename structure bash completed but am completely stuck.
#
# Below is what I have so far:
#
_opm_complete()
{
case $COMP_CWORD in
1)
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($( compgen -W "$(for x in /var/opm/opms/*; do echo $(basename ${x}); done)" -- $cur ) )
;;
2)
opts="fetch unpack prepare configure compile install package merge unmerge clean"
COMPREPLY=($(compgen -W "${opts}" "${COMP_WORDS[$COMP_CWORD]}"))
;;
*)
COMPREPLY=("")
;;
esac
}
complete -F _opm_complete opm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment