Skip to content

Instantly share code, notes, and snippets.

@trickart
Last active October 11, 2016 06:13
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 trickart/a7dc1f909e9ee95c665d to your computer and use it in GitHub Desktop.
Save trickart/a7dc1f909e9ee95c665d to your computer and use it in GitHub Desktop.
Completion of cyg-fast command for bash
_cyg-fast()
{
local cur prev mirrordir arch pkg localpkg
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [ -e /etc/setup/last-mirror ]; then
mirrordir="$(head -1 /etc/setup/last-mirror | sed 's/:/%3a/g;s/\//%2f/g')"
fi
arch="$(arch | sed -e 's/^i686$/x86/g')"
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $( compgen -W "install resume-install remove update show find describe packageof pathof" -- $cur))
elif [ $COMP_CWORD -ge 2 ]; then
if [ "${COMP_WORDS[1]}" = "install" ]; then
pkg="$(awk '/@/ { print $2 }' "/setup/$mirrordir/$arch/setup.ini" | tr '\n' ' ')"
COMPREPLY=( $( compgen -W "$pkg" -- $cur))
elif [ "${COMP_WORDS[1]}" = "remove" ]; then
localpkg="$(awk '/[^ ]+ [^ ]+ 0/ {print $1}' /etc/setup/installed.db | tr '\n' ' ')"
COMPREPLY=( $( compgen -W "$localpkg" -- $cur))
fi
fi
}
complete -F _cyg-fast cyg-fast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment