aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Mike Kelly <pioto@pioto.org> 2006-12-12 08:45:41 +0000
committerAvatar Mike Kelly <pioto@pioto.org> 2006-12-12 08:45:41 +0000
commit8d65263c6eaf77858033f4a15faa89ea64dc3135 (patch)
treebbda8664ffef94b89c050a9659867b35b5fb75bc
parent1469960adcfb06ac39d961bdd5ae7cf6177b6600 (diff)
downloadpaludis-8d65263c6eaf77858033f4a15faa89ea64dc3135.tar.gz
paludis-8d65263c6eaf77858033f4a15faa89ea64dc3135.tar.xz
Major rewrite. Should now complete efficiently on package names, and is aware of what action is being done, and limits options appropriately.
-rw-r--r--bash-completion/paludis217
1 files changed, 183 insertions, 34 deletions
diff --git a/bash-completion/paludis b/bash-completion/paludis
index f4979e0..1466449 100644
--- a/bash-completion/paludis
+++ b/bash-completion/paludis
@@ -5,13 +5,33 @@
# NOTE: This is still a work in progress, don't expect it to work well or
# properly right now.
+_paludis_packagenames() {
+ for names_cache in $(paludis --list-repositories --log-level silent |sed -n 's,^[[:space:]]*names_cache:[[:space:]]*\(.*\)$,\1,p')
+ do
+ pushd "${names_cache}" 1>/dev/null
+ echo *
+ popd 1>/dev/null
+ done
+}
+
+_paludis_dolist() {
+ paludis --list-${1} --log-level silent |sed -n 's,^\* \(.*\),\1,p'
+}
+
_paludis() {
- local cur prev opts
+ local cur prev opts action
+
+ local action_opts general_opts deplist_opts
+ local query_opts install_opts uninstall_opts sync_opts report_opts
+ local contents_opts owner_opts info_opts version_query_opts
+ local env_variable_query_opts conf_variable_query_opts
+ local list_opts regen_opts all_opts
+
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
- opts="--query -q \
+ action_opts="--query -q \
--install -i \
--uninstall -u \
--uninstall-unused \
@@ -35,23 +55,14 @@ _paludis() {
--list-dep-tag-categories \
--update-news \
--regenerate-installed-cache \
- --regenerate-installable-cache \
- --log-level \
+ --regenerate-installable-cache"
+ general_opts="--log-level \
--no-colour \
--no-color \
--config-suffix -c \
- --resume-command-template \
- --show-deps -D \
- --show-metadata -M \
- --pretend -p \
- --preserve-world -1 \
- --no-config-protection \
- --debug-build \
- --fetch -f \
- --show-install-reasons \
- --with-unused-dependencies \
- --with-dependencies \
- --dl-reinstall \
+ --resume-command-template"
+
+ deplist_opts="--dl-reinstall \
--dl-reinstall-scm \
--dl-upgrade \
--dl-installed-deps-pre \
@@ -61,19 +72,108 @@ _paludis() {
--dl-uninstalled-deps-runtime \
--dl-uninstalled-deps-post \
--dl-circular \
- --dl-fall-back \
- --repository \
+ --dl-fall-back"
+
+ query_opts="--show-deps -D \
+ --show-metadata -M"
+ install_opts="--pretend -p \
+ --preserve-world -1 \
+ --no-config-protection \
+ --debug-build \
+ --fetch -f \
+ --show-install-reasons \
+ ${deplist_opts}"
+ uninstall_opts="--pretend -p \
+ --preserve-world -1 \
+ --no-config-protection \
+ --show-install-reasons \
+ --with-unused-dependencies \
+ --with-dependencies \
+ ${deplist_opts}"
+ sync_opts=""
+ report_opts=""
+ contents_opts=""
+ owner_opts="--full-match"
+ info_opts=""
+ version_query_opts=""
+ env_variable_query_opts=""
+ conf_variable_query_opts=""
+ list_opts="--repository \
--category \
--package \
- --set \
- --full-match"
+ --set"
+ regen_opts=""
+
+ all_opts="${action_opts} ${general_opts} ${query_opts} ${install_opts} ${uninstall_opts} ${sync_opts} ${report_opts} ${contents_opts} ${owner_opts} ${version_query_opts} ${variable_query_opts} ${list_opts} ${regen_opts}"
+
+ local x
+ for x in "${COMP_WORDS[@]}" ; do
+ case "${x}" in
+ -q|--query)
+ action="query"
+ break
+ ;;
+ -i|--install)
+ action="install"
+ break
+ ;;
+ -u|--uninstall|--uninstall-unused)
+ action="uninstall"
+ break
+ ;;
+ -s|--sync)
+ action="sync"
+ break
+ ;;
+ -r|--report)
+ action="report"
+ break
+ ;;
+ -k|--contents)
+ action="contents"
+ break
+ ;;
+ -o|--owner)
+ action="owner"
+ break
+ ;;
+ -V|--version|-I|--info|-h|--help)
+ action="info"
+ break
+ ;;
+ --has-version|--best-version)
+ action="version_query"
+ break
+ ;;
+ --environment-variable)
+ action="env_variable_query"
+ break
+ ;;
+ --configuration-variable)
+ action="conf_variable_query"
+ break
+ ;;
+ --list-repositories|--list-categories|--list-packages|--list-sets|--list-sync-protocols|--list-repository-formats|--list-dep-tag-categories)
+ action="list"
+ break
+ ;;
+ --update-news|--regenerate-installed-cache|--regenerate-installable-cache)
+ action="regen"
+ break
+ ;;
+ esac
+ done
case "${cur}" in
-*)
- COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
+ local opts=
+ [[ -z "${action}" ]] && action="all"
+ opts="${action}_opts"
+
+ COMPREPLY=($(compgen -W "${general_opts} ${!opts}" -- "${cur}"))
return 0
;;
- *)
+ *)
case "${prev}" in
## Enum operators
--log-level)
@@ -114,34 +214,83 @@ _paludis() {
;;
## list specifiers
--repository)
- COMPREPLY=($(compgen -W "`paludis --no-colour --list-repositories --log-level silent |grep \"^*\" |cut -d\" \" -f2-`" -- "${cur}"))
+ COMPREPLY=($(compgen -W "$(_paludis_dolist repositories)" -- "${cur}"))
return 0
;;
--category)
- COMPREPLY=($(compgen -W "`paludis --no-colour --list-categories --log-level silent |grep \"^*\" |cut -d\" \" -f2-`" -- "${cur}"))
+ COMPREPLY=($(compgen -W "$(_paludis_dolist categories)" -- "${cur}"))
return 0
;;
--package)
- COMPREPLY=($(compgen -W "`paludis --no-colour --list-packages --log-level silent |grep \"^*\" |cut -d\" \" -f2-`" -- "${cur}"))
+ COMPREPLY=($(compgen -W "$(_paludis_packagenames)" -- "${cur}"))
return 0
;;
--set)
- COMPREPLY=($(compgen -W "`paludis --no-colour --list-sets --log-level silent |grep \"^\\*\" |cut -d\" \" -f2-`" -- "${cur}"))
+ COMPREPLY=($(compgen -W "$(_paludis_dolist sets)" -- "${cur}"))
return 0
;;
- --owner)
- COMPREPLY=($(compgen -o filenames -- "${cur}"))
+ --owner|-o)
+ COMPREPLY=($(compgen -f -- "${cur}"))
return 0
;;
+ #=*|>*|>*|~*)
+ # :
+ # ;;
*)
- # Do package name completion, etc
- # For now, just complete on set names and filenames
- COMPREPLY=($(compgen -W "`paludis --no-colour --list-sets --log-level silent |grep \"^*\" |cut -d\" \" -f2-`" -- "${cur}") \
- $(compgen -o default -- "${cur}"))
- return 0
+ case "${action}" in
+ sync)
+ COMPREPLY=($(compgen -W "$(_paludis_dolist repositories)" -- "${cur}"))
+ return 0
+ ;;
+ report|info|list|regen)
+ return 0
+ ;;
+ owner)
+ COMPREPLY=($(compgen -f -- "${cur}"))
+ return 0
+ ;;
+ conf_variable_query)
+ case "${prev}" in
+ -*)
+ COMPREPLY=($(compgen -W "$(_paludis_dolist repositories)" -- "${cur}"))
+ ;;
+ *)
+ COMPREPLY=($(compgen -W "$(paludis --log-level silent --list-repositories --repository ${prev} |sed -n 's,^ \([^:]*\).*,\1,p')" -- "${cur}"))
+ ;;
+ esac
+ return 0
+
+ ;;
+ query|install|uninstall|contents|version_query|env_variable_query)
+ if [[ "${action}" == "env_variable_query" \
+ && "${prev}" != -* ]]
+ then
+ COMPREPLY=($(compgen -W "$(paludis --log-level silent --info |sed -n 's,^ \([A-Z][^:]*\):.*,\1,p')" -- "${cur}"))
+ return 0
+ fi
+ # default - match on package names
+ case "${cur}" in
+ */*)
+ local catname=${cur%/*}
+ COMPREPLY=($(compgen -W "$(paludis --list-packages --log-level silent --category ${catname} |sed -n 's,^\* \(.*\),\1,p')" -- "${cur}"))
+ return 0
+ ;;
+ *)
+ # Do set name, package name, and category name completion
+ COMPREPLY=(
+ $(compgen -W "$(_paludis_dolist sets)" -- "${cur}")
+ $(compgen -W "$(_paludis_dolist categories)" -- "${cur}")
+ $(compgen -W "$(_paludis_packagenames)" -- "${cur}")
+ $(compgen -f -- "${cur}")
+ )
+ return 0
+ ;;
+ esac
+ ;;
+ esac
;;
esac
;;
esac
}
-complete -F _paludis paludis
+complete -o filenames -F _paludis paludis