summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/bash_completion348
-rw-r--r--contrib/zsh_completion320
-rw-r--r--lib/libalpm/package.c2
3 files changed, 668 insertions, 2 deletions
diff --git a/contrib/bash_completion b/contrib/bash_completion
new file mode 100644
index 00000000..9c378d63
--- /dev/null
+++ b/contrib/bash_completion
@@ -0,0 +1,348 @@
+# vim: set ft=sh:
+# file: /etc/bash_completion.d/pacman
+
+# Bash completion for ArchLinux
+# Original: v.1.1 Manolis Tzanidakis <mtzanidakis@freemail.gr>
+#
+# Distributed under the terms of the GNU General Public License, v2 or later.
+#
+
+## Changelog ####################################################
+# #
+# * 1.1 (20040117) #
+# - Code cleanup #
+# - Updated to pacman 2.7.2-2 #
+# * 20040216 (orelien) #
+# - Improved available_{pkgs,groups) functions #
+# - Added support for querying groups #
+# #
+#################################################################
+
+## initial functions
+#
+
+rem_selected ()
+{
+ # (Adapted from bash_completion by Ian Macdonald <ian@caliban.org>)
+ # This removes any options from the list of completions that have
+ # already been specified on the command line.
+ COMPREPLY=($(echo "${COMP_WORDS[@]}" | \
+ (while read -d ' ' i; do
+ [ "${i}" == "" ] && continue
+ # flatten array with spaces on either side,
+ # otherwise we cannot grep on word boundaries of
+ # first and last word
+ COMPREPLY=" ${COMPREPLY[@]} "
+ # remove word from list of completions
+ COMPREPLY=(${COMPREPLY/ ${i%% *} / })
+ done
+ echo ${COMPREPLY[@]})))
+ return 0
+}
+
+_available_repos ()
+{
+ COMPREPLY=( $( compgen -W "$(grep '\[' /etc/pacman.conf | grep -v -e 'options' -e '^#' | tr -d '[]' )" -- $cur ) )
+}
+
+_installed_pkgs ()
+{
+ local installed_pkgs
+ installed_pkgs=$( ls /var/lib/pacman/local/ )
+ COMPREPLY=( $( compgen -W "$( for i in $installed_pkgs; do echo ${i%-*-*}; done )" -- $cur ) )
+}
+
+_available_pkgs ()
+{
+ #find balks easilly on a find /foo/*/* type dir, especially one like
+ # /var/lib/pacman/*/*
+ # This little change-up removes the find *and* only uses enabled repos
+ local available_pkgs
+ local enabled_repos
+ enabled_repos=$( grep '\[' /etc/pacman.conf | grep -v -e 'options' -e '^#' | tr -d '[]' )
+ available_pkgs=$( for r in $enabled_repos; do echo /var/lib/pacman/$r/*; done )
+ COMPREPLY=( $( compgen -W "$( for i in $available_pkgs; do j=${i##*/}; echo ${j%-*-*}; done )" -- $cur ) )
+}
+
+_installed_groups ()
+{
+ local installed_groups
+ installed_groups=$( find /var/lib/pacman/local -name desc -exec sed -ne '/%GROUPS%/,/^$/{//d; p}' {} \; | sort -u )
+ COMPREPLY=( $( compgen -W "$( for i in $installed_groups; do echo ${i%-*-*}; done )" -- $cur ) )
+}
+
+_available_groups ()
+{
+ #find balks easilly on a find /foo/*/* type dir, especially one like
+ # /var/lib/pacman/*/*
+ # This little change-up removes the find *and* only uses enabled repos
+ local available_groups
+ local enabled_repos
+ enabled_repos=$( grep '\[' /etc/pacman.conf | grep -v -e 'options' -e '^#' | tr -d '[]' )
+ available_groups=$( for r in $enabled_repos; do sed '/%GROUPS%/,/^$/{//d; p}' /var/lib/pacman/$r/*/desc | sort -u; done )
+ COMPREPLY=( $( compgen -W "$( for i in $available_groups; do echo ${i%-*-*}; done )" -- $cur ) )
+}
+
+## init (/etc/rc.d) script completion (quick 'n' dirty ;-)
+#
+
+complete -W "start stop restart" \
+ $(for i in /etc/rc.d/*; do echo ${i##*/}; done)
+
+## makepkg completion
+#
+
+_makepkg ()
+{
+ local cur prev
+ COMPREPLY=()
+ cur=${COMP_WORDS[COMP_CWORD]}
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(p|w))
+ _filedir
+ return 0
+ ;;
+ --help|--cleancache|--genmd5)
+ COMPREPLY=''
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-b --builddeps \
+ -c --clean \
+ -C --cleancache \
+ -d --nodeps \
+ -f --force \
+ -g --genmd5 \
+ -h --help \
+ -i --install \
+ -m --nocolor \
+ -n --nostrip \
+ -r --rmdeps \
+ -s --syncdeps \
+ -p -w' -- $cur ) )
+ fi
+
+ rem_selected
+}
+complete -o default -F _makepkg makepkg
+
+## pacman completion
+#
+
+_instring ()
+{
+ str="${1}"
+ shift 1
+ for c in "${@}"; do
+ if [ $(expr index "${str}" "${c}") -gt 0 ]; then
+ return 0
+ fi
+ done
+ return 1
+}
+
+_pacman ()
+{
+ local a arg toparse op mod cur
+ COMPREPLY=()
+
+ # This argument parsing is done so we can check for flag existance later
+ # right now it's a tad crappy, but does the job
+ for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do
+ a=${COMP_WORDS[i]}
+ arg="${a:0:2}"
+ toparse="${a:2}"
+
+ case "${arg}" in
+ -@(A|U|F|R|S|Q|h|V))
+ op="${arg/-}"
+ mod="${mod}${a:2}"
+ ;;
+ --)
+ arg="${a:2}"
+ case "${arg}" in
+ add) op="A" ;;
+ remove) op="R" ;;
+ upgrade) op="U" ;;
+ freshen) op="F" ;;
+ query) op="Q" ;;
+ sync) op="S" ;;
+ help) op="h" ;;
+ version) op="V" ;;
+ verbose) mod="${mod}v" ;;
+ root) mod="${mod}r" ;;
+ dbpath) mod="${mod}b" ;;
+ nodeps) mod="${mod}d" ;;
+ force) mod="${mod}f" ;;
+ groups) mod="${mod}g" ;;
+ info) mod="${mod}i" ;;
+ list) mod="${mod}l" ;;
+ print-uris) mod="${mod}p" ;;
+ search) mod="${mod}s" ;;
+ sysupgrade) mod="${mod}u" ;;
+ downloadonly) mod="${mod}w" ;;
+ refresh) mod="${mod}y" ;;
+ orphans) mod="${mod}e" ;;
+ foreign) mod="${mod}m" ;;
+ owns) mod="${mod}o" ;;
+ file) mod="${mod}p" ;;
+ search) mod="${mod}s" ;;
+ cascade) mod="${mod}c" ;;
+ nodeps) mod="${mod}d" ;;
+ dbonly) mod="${mod}k" ;;
+ nosave) mod="${mod}n" ;;
+ recursive) mod="${mod}s" ;;
+ esac ;;
+ *) toparse="${a}" ;;
+ esac
+
+ arglen=$(( ${#toparse}-1 ))
+ for c in $(seq 0 "${arglen}"); do
+ arg=${toparse:$c:1}
+ [ "${arg}" != "-" ] && mod="${mod}${arg}"
+ done
+ done
+
+ cur=${COMP_WORDS[COMP_CWORD]}
+
+ if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '\
+ -A --add \
+ -F --freshen \
+ -h --help \
+ -Q --query \
+ -R --remove \
+ -S --sync \
+ -U --upgrade \
+ -V --version \
+ ' -- $cur ) )
+ rem_selected
+ return 0
+ fi
+
+ if [[ "$cur" == -* ]]; then
+ case "${op}" in
+ A|U|F)
+ COMPREPLY=( $( compgen -W '\
+ -d --nodeps \
+ -f --force \
+ -h --help \
+ --config \
+ --noconfirm \
+ --noprogressbar \
+ -v --verbose \
+ -r --root \
+ -b --dbpath \
+ ' -- $cur ) )
+ return 0
+ ;;
+ R)
+ COMPREPLY=( $( compgen -W '\
+ -c --cascade \
+ -d --nodeps \
+ -f --force \
+ -h --help \
+ -k --dbonly \
+ -n --nosave \
+ -s --recursive \
+ --config \
+ --noconfirm \
+ --noprogressbar \
+ -v --verbose \
+ -r --root \
+ -b --dbpath \
+ ' -- $cur ) )
+ return 0
+ ;;
+ S)
+ COMPREPLY=( $( compgen -W '\
+ -c --clean \
+ -d --nodeps \
+ -f --force \
+ -g --groups \
+ -h --help \
+ -i --info \
+ -l --list \
+ -p --print-uris \
+ -s --search \
+ -u --sysupgrade \
+ -w --downloadonly \
+ -y --refresh \
+ --config \
+ --noconfirm \
+ --noprogressbar \
+ -v --verbose \
+ -r --root \
+ -b --dbpath \
+ ' -- $cur ) )
+ return 0
+ ;;
+ Q)
+ COMPREPLY=( $( compgen -W '\
+ -e --orphans \
+ -g --groups \
+ -h --help \
+ -i --info \
+ -l --list \
+ -m --foreign \
+ -o --owns \
+ -p --file \
+ -s --search \
+ --config \
+ --noconfirm \
+ --noprogressbar \
+ -v --verbose \
+ -r --root \
+ -b --dbpath \
+ ' -- $cur ) )
+ return 0
+ ;;
+ esac
+ rem_selected
+ else
+ case "${op}" in
+ A|U)
+ COMPREPLY=( $( compgen -d -- "$cur" ) \
+ $( compgen -f -X '!*.pkg.tar.gz' -- "$cur" ) )
+ return 0
+ ;;
+ h|V)
+ COMPREPLY=''
+ return 0
+ ;;
+ Q)
+ if _instring $mod g; then
+ _installed_groups
+ elif _instring $mod o; then
+ COMPREPLY=( $( compgen -d -- "$cur" ) \
+ $( compgen -f -- "$cur" ) )
+ elif _instring $mod p; then
+ COMPREPLY=( $( compgen -d -- "$cur" ) \
+ $( compgen -f -X '!*.pkg.tar.gz' -- "$cur" ) )
+ else
+ _installed_pkgs
+ fi
+ return 0
+ ;;
+ R)
+ _installed_pkgs
+ return 0
+ ;;
+ S)
+ if _instring $mod l; then
+ _available_repos
+ else
+ _available_pkgs
+ fi
+ return 0
+ ;;
+ esac
+ fi
+
+ rem_selected
+}
+complete -o filenames -F _pacman pacman
diff --git a/contrib/zsh_completion b/contrib/zsh_completion
new file mode 100644
index 00000000..d7e14864
--- /dev/null
+++ b/contrib/zsh_completion
@@ -0,0 +1,320 @@
+# file: /usr/share/zsh/site-functions/_pacman
+# use the following in your zsh config:
+# compdef pacman pacman.static=pacman
+
+typeset -A opt_args
+
+# options for passing to _arguments: main pacman commands
+_pacman_opts_commands=(
+ '-A[Add a package to the system]'
+ '-F[Upgrade an installed package]'
+ '-Q[Query the package database]'
+ '-R[Remove a package from the system]'
+ '-S[Synchronize packages]'
+ '-U[Upgrade a package]'
+ '-V[Display version and exit]'
+ '-h[Display usage]'
+)
+
+# options for passing to _arguments: options common to all commands
+_pacman_opts_common=(
+ '-b[Alternate database location]:database_location:_files -/'
+ '-h[Display syntax for the given operation]'
+ '-r[Set alternate installation root]:installation root:_files -/'
+ '-v[Be more verbose]'
+ '--config[An alternate configuration file]:config file:_files'
+ '--noconfirm[Do not ask for confirmation]'
+)
+
+# options for passing to _arguments: options for --add, --freshen and --update commands
+_pacman_opts_pkgfile=(
+ '-d[Skip dependency checks]'
+ '-f[Overwrite conflicting files]'
+ '*:package file:_files -g "*.pkg.tar.gz(.)"'
+)
+
+# options for passing to _arguments: subactions for --query command
+_pacman_opts_query_actions=(
+ '-e[List orphaned packages]:*:orphans:->query_orphans'
+ '-g[View all members of a package group]:*:package groups:->query_group'
+ '-o[Query the package that owns a file]:file:_files'
+ '-p[Package file to query]:*:package file:->query_file'
+ '-s[Search package names and descriptions]:*:search text:->query_search'
+)
+
+# options for passing to _arguments: options for --query and subcommands
+_pacman_opts_query_modifiers=(
+ '-i[View package information]'
+ '-l[List package contents]'
+)
+
+# options for passing to _arguments: options for --remove command
+_pacman_opts_remove=(
+ '-c[Remove all dependent packages]'
+ '-d[Skip dependency checks]'
+ '-k[Only remove database entry, do not remove files]'
+ '-n[Remove protected configuration files]'
+ '-s[Remove dependencies not required by other packages]'
+ '*:installed package:_pacman_completions_installed_packages'
+)
+
+# options for passing to _arguments: options for --sync command
+_pacman_opts_sync_actions=(
+ '*-c[Remove old packages from cache]:*:clean:->sync_clean'
+ '-g[View all members of a package group]:*:package groups:->sync_group'
+ '-s[Search package names and descriptions]:*:search text:->sync_search'
+)
+
+# options for passing to _arguments: options for --sync command
+_pacman_opts_sync_modifiers=(
+ '-d[Skip dependency checks]'
+ '-f[Overwrite conflicting files]'
+ '-i[View package information]'
+ '-l[List all packages in a repository]'
+ '-p[Print download URIs for each package to be installed]'
+ '-u[Upgrade all out-of-date packages]'
+ '-w[Download packages only]'
+ '-y[Download fresh package databases]'
+ '*--ignore[Ignore a package upgrade]:package:_pacman_completions_installed_packages'
+)
+
+# handles --action subcommand
+_pacman_action_add() {
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_pkgfile[@]"
+}
+
+# handles --freshen subcommand
+_pacman_action_freshen() {
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_pkgfile[@]"
+}
+
+# handles --help subcommand
+_pacman_action_help() {
+ _arguments -s : \
+ "$_pacman_opts_commands[@]"
+}
+
+# handles cases where no subcommand has yet been given
+_pacman_action_none() {
+ _arguments -s : \
+ "$_pacman_opts_commands[@]"
+}
+
+# handles --query subcommand
+_pacman_action_query() {
+ local context state line
+ typeset -A opt_args
+
+# _arguments -s : \
+# "$_pacman_opts_common[@]" \
+# "$_pacman_opts_query_actions[@]" \
+# "$_pacman_opts_query_modifiers[@]"
+
+ case $state in
+ query_file)
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_query_modifiers[@]" \
+ '*:package file:_files -g "*.pkg.tar.gz"'
+ ;;
+ query_group)
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_query_modifiers[@]" \
+ '*:groups:_pacman_completions_installed_groups'
+ ;;
+ query_orphans)
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_query_modifiers[@]"
+ ;;
+ query_owner)
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_query_modifiers[@]" \
+ '*:file:_files'
+ ;;
+ query_search)
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_query_modifiers[@]" \
+ '*:search text: '
+ ;;
+ *)
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_query_actions[@]" \
+ "$_pacman_opts_query_modifiers[@]" \
+ '*:package:_pacman_completions_installed_packages'
+ ;;
+ esac
+}
+
+# handles --remove subcommand
+_pacman_action_remove() {
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_remove[@]"
+}
+
+# handles --sync subcommand
+_pacman_action_sync() {
+ local context state line
+ typeset -A opt_args
+
+# _arguments -s : \
+# "$_pacman_opts_common[@]" \
+# "$_pacman_opts_sync_actions[@]" #\
+# #"$_pacman_opts_sync_modifiers[@]"
+
+ case $state in
+ sync_clean)
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_sync_modifiers[@]" \
+ '*-c[Remove old packages from cache]' \
+ ;;
+ sync_group)
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_sync_modifiers[@]" \
+ '*:package group:_pacman_completions_all_groups'
+ ;;
+ sync_search)
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_sync_modifiers[@]" \
+ '*:search text: '
+ ;;
+ *)
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_sync_modifiers[@]" \
+ '*:package:_pacman_completions_all_packages'
+ ;;
+ esac
+}
+
+# handles --upgrade subcommand
+_pacman_action_upgrade() {
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_pkgfile[@]"
+}
+
+# handles --version subcommand
+_pacman_action_version() {
+ # no further arguments
+ return 0
+}
+
+# provides completions for package groups
+_pacman_completions_all_groups() {
+ local -a cmd groups
+ _pacman_get_command
+ groups=( $(_call_program groups $cmd[@] -Sg | grep -e \^$PREFIX) )
+ compadd "$@" -a groups
+}
+
+# provides completions for packages available from repositories
+_pacman_completions_all_packages() {
+ local -a cmd packages repositories
+
+ repositories=( $(_call_program repositories cat /etc/pacman.conf | grep "^\[" | sed "s,\(\[\|\]\),,g" | grep -v "^options" | sort -u) )
+ # these can be specified as either 'package' or 'repository/package'
+ if [[ "$PREFIX" == "" ]] ; then
+ packages=( $(_call_program packages ls /var/lib/pacman/${^repositories} | grep -v "^/" | sed "s,\-[^-]*\-[^-]*$,," | sort -u) )
+ else
+ packages=( $(_call_program packages ls /var/lib/pacman/${^repositories} | grep -v "^/" | grep -e \^$PREFIX | sed "s,\-[^-]*\-[^-]*$,," | sort -u) )
+ fi
+ compadd "$@" -a packages
+}
+
+# provides completions for package groups
+_pacman_completions_installed_groups() {
+ local -a cmd groups
+ _pacman_get_command
+ groups=( $(_call_program installed_groups $cmd[@] -Qg | cut -d' ' -f1 | grep -e \^$PREFIX | sort -u) )
+ compadd "$@" -a groups
+}
+
+# provides completions for installed packages
+_pacman_completions_installed_packages() {
+ local -a cmd packages
+ packages=( $(_call_program installed_packages ls /var/lib/pacman/local | grep "^$PREFIX" | sed "s,\-[^-]*\-[^-]*$,,") )
+ compadd "$@" -a packages
+}
+
+# provides completions for repository names
+_pacman_completions_repositories() {
+ local -a cmd repositories
+ repositories=( $(_call_program repositories cat /etc/pacman.conf | grep "^\[" | sed "s,\(\[\|\]\),,g" | grep -v "^options" | grep "^$PREFIX" | sort -u) )
+ compadd "$@" -a repositories
+}
+
+# builds command for invoking pacman in a _call_program command - extracts
+# relevant options already specified (config file, etc)
+# $cmd must be declared by calling function
+_pacman_get_command() {
+ # this is mostly nicked from _perforce
+ cmd=( "pacman" )
+ integer i
+ for (( i = 2; i < CURRENT - 1; i++ )); do
+ if [[ ${words[i]} = "--config" || ${words[i]} = "--root" ]]; then
+ cmd+=( ${words[i,i+1]} )
+ fi
+ done
+}
+
+# main dispatcher
+_pacman() {
+ case $words[2] in
+ -A*) _pacman_action_add ;;
+ -F*) _pacman_action_freshen ;;
+ -Qg) # ipkg groups
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_query_modifiers[@]" \
+ '*:groups:_pacman_completions_installed_groups'
+ ;;
+ -Qo) # file *.pkg.tar.gz
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_query_modifiers[@]" \
+ '*:package file:_files'
+ ;;
+ -Qp) # file *.pkg.tar.gz
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_query_modifiers[@]" \
+ '*:package file:_files -g "*.pkg.tar.gz"'
+ ;;
+ -Q*) _pacman_action_query ;;
+ -R*) _pacman_action_remove ;;
+ -Sl) # repos
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_sync_modifiers[@]" \
+ '*:package repo:_pacman_completions_repositories' \
+ ;;
+ -Sg) # pkg groups
+ _arguments -s : \
+ "$_pacman_opts_common[@]" \
+ "$_pacman_opts_sync_modifiers[@]" \
+ '*:package group:_pacman_completions_all_groups'
+ ;;
+ -S*) _pacman_action_sync ;;
+ -U*) _pacman_action_upgrade ;;
+ -V*) _pacman_action_version ;;
+ -h*) _pacman_action_help ;;
+ - ) _pacman_action_none ;;
+ * ) return 1 ;;
+ esac
+}
+
+# run the main dispatcher
+_pacman "$@"
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 85439a6c..c8d5989c 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -156,12 +156,10 @@ int alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg)
/* package should be ignored (IgnorePkg) */
_alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (%s)"),
local_pkg->name, local_pkg->version, pkg->version);
- cmp = 0;
} else if(_alpm_pkg_istoonew(pkg)) {
/* package too new (UpgradeDelay) */
_alpm_log(PM_LOG_WARNING, _("%s-%s: delaying upgrade of package (%s)"),
local_pkg->name, local_pkg->version, pkg->version);
- cmp = 0;
}
}