Skip to content

Instantly share code, notes, and snippets.

@hirose31
Created July 9, 2013 11:14
Show Gist options
  • Save hirose31/5956585 to your computer and use it in GitHub Desktop.
Save hirose31/5956585 to your computer and use it in GitHub Desktop.
# -*- mode: sh -*-
_cpanm() {
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
opt_bool=(--verbose --quiet --interactive --force --notest --test-only --sudo --installdeps --showdeps --reinstall --mirror-only --prompt --self-contained --self-upgrade --version --dev
--with-all-features --with-develop --without-develop --pp --pureperl
)
opt_bool=(${opt_bool[@]} -v -q -f -n -S -V)
opt_take_url=(--mirror)
opt_take_dist=(--info --look --uninstall --scandeps --showdeps)
opt_take_dist=(${opt_take_dist[@]} -U)
opt_take_dir=(--local-lib --local-lib-contained --save-dists)
opt_take_dir=(${opt_take_dir[@]} -l -L)
opt_take_int=(--auto-cleanup)
opt_take_other=(--with-feature --without-feature)
OIFS="$IFS"
IFS='|'
pat_take_url="${opt_take_url[*]}"
pat_take_dist="${opt_take_dist[*]}"
pat_take_dir="${opt_take_dir[*]}"
pat_take_int="${opt_take_int[*]}"
pat_take_other="${opt_take_other[*]}"
IFS="$OIFS"
if [[ $prev =~ ^(${pat_take_url})$ ]]; then
COMPREPLY=($(compgen -W "http:// https://" -- "$cur"))
elif [[ $prev =~ ^(${pat_take_dist})$ ]]; then
COMPREPLY=($(compgen -W "<Str> Dist::Name" -- "$cur"))
elif [[ $prev =~ ^(${pat_take_dir})$ ]]; then
COMPREPLY=($(compgen -d -- "$cur"))
elif [[ $prev =~ ^(${pat_take_int})$ ]]; then
COMPREPLY=($(compgen -W "<Int> Value" -- "$cur"))
elif [[ $prev =~ ^(${pat_take_other})$ ]]; then
COMPREPLY=($(compgen -W "<Str> Value" -- "$cur"))
else
COMPREPLY=($(compgen -W "${opt_bool[*]} ${opt_take_url[*]} ${opt_take_dist[*]} ${opt_take_dir[*]} ${opt_take_int[*]} ${opt_take_other[*]}" -- "$cur"))
fi
}
complete -F _cpanm cpanm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment