From 882f4714ac75732cb69999ea4ab82e8662f53031 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 17 Jul 2015 14:15:28 +0200 Subject: [PATCH] pacman completion: Turn into regular completion This used to be a function because we didn't have complete -w Use that and it becomes a bit simpler. This also simplifies the code in a few other ways (like removing a useless-use-of-cat) and adds comments about a few edgecases. --- share/completions/pacman-color.fish | 4 +- share/completions/pacman.fish | 128 +++++++++++++++++++- share/completions/pacmatic.fish | 4 +- share/completions/pacsrv.fish | 3 +- share/completions/yaourt.fish | 4 +- share/functions/__fish_complete_pacman.fish | 112 ----------------- 6 files changed, 131 insertions(+), 124 deletions(-) delete mode 100644 share/functions/__fish_complete_pacman.fish diff --git a/share/completions/pacman-color.fish b/share/completions/pacman-color.fish index 6a6377f26..a32caa550 100644 --- a/share/completions/pacman-color.fish +++ b/share/completions/pacman-color.fish @@ -1,3 +1 @@ - -__fish_complete_pacman pacman-color - +complete -c pacman-color -w pacman diff --git a/share/completions/pacman.fish b/share/completions/pacman.fish index 33949b95f..7880e7003 100644 --- a/share/completions/pacman.fish +++ b/share/completions/pacman.fish @@ -1,3 +1,129 @@ +# Completions for pacman +# Author: Giorgio Lando +# Updated by maxfl, SanskritFritz, faho -__fish_complete_pacman pacman +set -l progname pacman +set -l listinstalled "(pacman -Q | tr ' ' \t)" +# This might be an issue if another package manager is also installed (e.g. for containers) +set -l listall "(__fish_print_packages)" +set -l listrepos "(grep '^\[.\+\]' /etc/pacman.conf | sed 's/[]\[]//g')" +set -l listgroups "(pacman -Sg | sed 's/\(.*\)/\1\tPackage group/g')" + +set -l noopt '__fish_contains_opt -s S -s D -s Q -s R -s U -s T database query sync remove upgrade deptest' +set -l database '__fish_contains_opt -s D database' +set -l query '__fish_contains_opt -s Q query' +set -l remove '__fish_contains_opt -s R remove' +set -l sync '__fish_contains_opt -s S sync' +set -l upgrade '__fish_contains_opt -s U upgrade' + +# By default fish expands the arguments with the option which is not desired +# due to performance reasons. +# This will make sure we are expanding an argument and not an option: +set -l argument 'not expr -- (commandline --current-token) : "^-.*" > /dev/null' + +complete -c pacman -e +complete -c pacman -f +# Primary operations +complete -c $progname -s D -f -l database -n $noopt -d 'Modify the package database' +complete -c $progname -s Q -f -l query -n $noopt -d 'Query the package database' +complete -c $progname -s R -f -l remove -n $noopt -d 'Remove packages from the system' +complete -c $progname -s S -f -l sync -n $noopt -d 'Synchronize packages' +complete -c $progname -s T -f -l deptest -n $noopt -d 'Check dependencies' +complete -c $progname -s U -f -l upgrade -n $noopt -d 'Upgrade or add a local package' +complete -c $progname -s V -f -l version -d 'Display version and exit' +complete -c $progname -s h -f -l help -d 'Display help' + +# General options +complete -c $progname -s b -l dbpath -d 'Alternative database location' -xa '(__fish_complete_directories)' +complete -c $progname -s r -l root -d 'Alternative installation root' +complete -c $progname -s v -l verbose -d 'Output more status messages' +complete -c $progname -l arch -d 'Alternate architecture' -f +complete -c $progname -l cachedir -d 'Alternative package cache location' +complete -c $progname -l config -d 'Alternate config file' +complete -c $progname -l debug -d 'Display debug messages' -f +complete -c $progname -l gpgdir -d 'GPG directory to verify signatures' +complete -c $progname -l logfile -d 'Specify alternative log file' +complete -c $progname -l noconfirm -d 'Bypass any question' -f + +# Transaction options (sync, remove, upgrade) +for condition in sync remove upgrade + complete -c $progname -n $$condition -s d -l nodeps -d 'Skip [all] dependency checks' -f + complete -c $progname -n $$condition -l dbonly -d 'Modify database entry only' -f + complete -c $progname -n $$condition -l noprogressbar -d 'Do not display progress bar' -f + complete -c $progname -n $$condition -l noscriptlet -d 'Do not execute install script' -f + complete -c $progname -n $$condition -s p -l print -d 'Dry run, only print targets' -f + complete -c $progname -n $$condition -l print-format -x -d 'Specify printf-like format' -f +end + +# Database and upgrade options (database, sync, upgrade) +for condition in database sync upgrade + complete -c $progname -n $$condition -l asdeps -d 'Mark PACKAGE as dependency' -f + complete -c $progname -n $$condition -l asexplicit -d 'Mark PACKAGE as explicitly installed' -f +end + +# Upgrade options (sync, upgrade) +for condition in sync upgrade + complete -c $progname -n $$condition -l force -d 'Bypass file conflict checks' -f + complete -c $progname -n $$condition -l ignore -d 'Ignore upgrade of PACKAGE' -xa "$listinstalled" -f + complete -c $progname -n $$condition -l ignoregroup -d 'Ignore upgrade of GROUP' -xa "$listgroups" -f + complete -c $progname -n $$condition -l needed -d 'Do not reinstall up-to-date targets' -f + complete -c $progname -n $$condition -l recursive -d 'Recursively reinstall all dependencies' -f +end + +# Query and sync options +for condition in query sync + complete -c $progname -n $$condition -s g -l groups -d 'Display all packages in GROUP' -xa "$listgroups" -f + complete -c $progname -n $$condition -s i -l info -d 'Display information on PACKAGE' -f + complete -c $progname -n $$condition -s q -l quiet -d 'Show less information' -f + complete -c $progname -n $$condition -s s -l search -r -d 'Search packages for regexp' -f +end + +# Query options +complete -c $progname -n $query -s c -l changelog -d 'View the change log of PACKAGE' -f +complete -c $progname -n $query -s d -l deps -d 'List only non-explicit packages (dependencies)' -f +complete -c $progname -n $query -s e -l explicit -d 'List only explicitly installed packages' -f +complete -c $progname -n $query -s k -l check -d 'Check if all files owned by PACKAGE are present' -f +complete -c $progname -n $query -s l -l list -d 'List all files owned by PACKAGE' -f +complete -c $progname -n $query -s m -l foreign -d 'List all packages not in the database' -f +complete -c $progname -n $query -s o -l owns -r -d 'Search for the package that owns FILE' -xa '' -f +complete -c $progname -n $query -s p -l file -d 'Apply the query to a package file, not package' -xa '' -f +complete -c $progname -n $query -s t -l unrequired -d 'List only unrequired packages' -f +complete -c $progname -n $query -s u -l upgrades -d 'List only out-of-date packages' -f +complete -c $progname -n "$query; and $argument" -d 'Installed package' -xa $listinstalled -f + +# Remove options +complete -c $progname -n $remove -s c -l cascade -d 'Also remove packages depending on PACKAGE' -f +complete -c $progname -n $remove -s n -l nosave -d 'Ignore file backup designations' -f +complete -c $progname -n $remove -s s -l recursive -d 'Also remove dependencies of PACKAGE' -f +complete -c $progname -n $remove -s u -l unneeded -d 'Only remove targets not required by PACKAGE' -f +complete -c $progname -n "$remove; and $argument" -d 'Installed package' -xa $listinstalled -f + +# Sync options +complete -c $progname -n $sync -s c -l clean -d 'Remove [all] packages from cache' +complete -c $progname -n $sync -s l -l list -xa "$listrepos" -d 'List all packages in REPOSITORY' +complete -c $progname -n "$sync; and not __fish_contains_opt -s u sysupgrade" -s u -l sysupgrade -d 'Upgrade all packages that are out of date' +complete -c $progname -n "$sync; and __fish_contains_opt -s u sysupgrade" -s u -l sysupgrade -d 'Also downgrade packages' +complete -c $progname -n $sync -s w -l downloadonly -d 'Only download the target packages' +complete -c $progname -n $sync -s y -l refresh -d 'Download fresh copy of the package list' +complete -c $progname -n "$argument; and $sync" -xa "$listall $listgroups" + +# Upgrade options +# Theoretically, pacman reads packages in all formats that libarchive supports +# In practice, it's going to be tar.xz or tar.gz +# Using "pkg.tar.*" here would change __fish_complete_suffix's descriptions to "unknown" +complete -c $progname -n "$upgrade; and $argument" -xa '(__fish_complete_suffix pkg.tar.xz)' -d 'Package file' +complete -c $progname -n "$upgrade; and $argument" -xa '(__fish_complete_suffix pkg.tar.gz)' -d 'Package file' + +set -e progname +set -e listinstalled +set -e listall +set -e listrepos +set -e listgroups +set -e noopt +set -e database +set -e query +set -e remove +set -e sync +set -e upgrade +set -e argument diff --git a/share/completions/pacmatic.fish b/share/completions/pacmatic.fish index b3e236d32..36d84624d 100644 --- a/share/completions/pacmatic.fish +++ b/share/completions/pacmatic.fish @@ -1,3 +1 @@ - -__fish_complete_pacman pacmatic - +complete -c pacmatic -w pacman diff --git a/share/completions/pacsrv.fish b/share/completions/pacsrv.fish index 94d5cb182..6ca7ac0a0 100644 --- a/share/completions/pacsrv.fish +++ b/share/completions/pacsrv.fish @@ -1,2 +1 @@ - -__fish_complete_pacman pacsrv +complete -c pacsrc -w pacman diff --git a/share/completions/yaourt.fish b/share/completions/yaourt.fish index aece613f6..9e19cca46 100644 --- a/share/completions/yaourt.fish +++ b/share/completions/yaourt.fish @@ -1,3 +1 @@ - -__fish_complete_pacman yaourt - +complete -c yaourt -w pacman diff --git a/share/functions/__fish_complete_pacman.fish b/share/functions/__fish_complete_pacman.fish deleted file mode 100644 index 6e3baa0db..000000000 --- a/share/functions/__fish_complete_pacman.fish +++ /dev/null @@ -1,112 +0,0 @@ -function __fish_complete_pacman -d 'Complete pacman (ARCH package manager)' --argument-names progname - # Completions for pacman - # Author: Giorgio Lando - # Updated by maxfl, SanskritFritz. - - set -q progname[1]; or set -l progname pacman - - set -l listinstalled "(pacman -Q | tr ' ' \t)" - set -l listall "(__fish_print_packages)" - set -l listrepos "(cat /etc/pacman.conf | grep '^\[.\+\]' | sed 's/[]\[]//g')" - set -l listgroups "(pacman -Sg | sed 's/\(.*\)/\1\tPackage group/g')" - - set -l noopt 'commandline | not sgrep -qe "-[a-z]*[DQRSTU]\|--database\|--query\|--sync\|--remove\|--upgrade\|--deptest"' - set -l database 'commandline | sgrep -qe "-[a-z]*D\|--database"' - set -l query 'commandline | sgrep -qe "-[a-z]*Q\|--query"' - set -l remove 'commandline | sgrep -qe "-[a-z]*R\|--remove"' - set -l sync 'commandline | sgrep -qe "-[a-z]*S\|--sync"' - set -l upgrade 'commandline | sgrep -qe "-[a-z]*U\|--upgrade"' - - # By default fish expands the arguments with the option which is not desired - # due to performance reasons. - # This will make sure we are expanding an argument and not an option: - set -l argument 'not expr -- (commandline --current-token) : "^-.*" > /dev/null' - - # Primary operations - complete -c $progname -s D -f -l database -n $noopt -d 'Modify the package database' - complete -c $progname -s Q -f -l query -n $noopt -d 'Query the package database' - complete -c $progname -s R -f -l remove -n $noopt -d 'Remove packages from the system' - complete -c $progname -s S -f -l sync -n $noopt -d 'Synchronize packages' - complete -c $progname -s T -f -l deptest -n $noopt -d 'Check dependencies' - complete -c $progname -s U -f -l upgrade -n $noopt -d 'Upgrade or add a local package' - complete -c $progname -s V -f -l version -d 'Display version and exit' - complete -c $progname -s h -f -l help -d 'Display help' - - # General options - complete -c $progname -s b -l dbpath -d 'Alternative database location' -xa '(__fish_complete_directories)' - complete -c $progname -s r -l root -d 'Alternative installation root' - complete -c $progname -s v -l verbose -d 'Output more status messages' - complete -c $progname -l arch -d 'Alternate architecture' - complete -c $progname -l cachedir -d 'Alternative package cache location' - complete -c $progname -l config -d 'Alternate config file' - complete -c $progname -l debug -d 'Display debug messages' - complete -c $progname -l gpgdir -d 'GPG directory to verify signatures' - complete -c $progname -l logfile -d 'Specify alternative log file' - complete -c $progname -l noconfirm -d 'Bypass any question' - - # Transaction options (sync, remove, upgrade) - for condition in sync remove upgrade - complete -c $progname -n $$condition -s d -l nodeps -d 'Skip [all] dependency checks' - complete -c $progname -n $$condition -l dbonly -d 'Modify database entry only' - complete -c $progname -n $$condition -l noprogressbar -d 'Do not display progress bar' - complete -c $progname -n $$condition -l noscriptlet -d 'Do not execute install script' - complete -c $progname -n $$condition -s p -l print -d 'Dry run, only print targets' - complete -c $progname -n $$condition -l print-format -x -d 'Specify printf-like format' - end - - # Database and upgrade options (database, sync, upgrade) - for condition in database sync upgrade - complete -c $progname -n $$condition -l asdeps -d 'Mark PACKAGE as dependency' - complete -c $progname -n $$condition -l asexplicit -d 'Mark PACKAGE as explicitly installed' - end - - # Upgrade options (sync, upgrade) - for condition in sync upgrade - complete -c $progname -n $$condition -s f -l force -d 'Bypass file conflict checks' - complete -c $progname -n $$condition -l ignore -d 'Ignore upgrade of PACKAGE' -xa "$listinstalled" - complete -c $progname -n $$condition -l ignoregroup -d 'Ignore upgrade of GROUP' -xa "$listgroups" - complete -c $progname -n $$condition -l needed -d 'Do not reinstall up-to-date targets' - complete -c $progname -n $$condition -l recursive -d 'Recursively reinstall all dependencies' - end - - # Query and sync options - for condition in query sync - complete -c $progname -n $$condition -s g -l groups -d 'Display all packages in GROUP' -xa "$listgroups" - complete -c $progname -n $$condition -s i -l info -d 'Display information on PACKAGE' - complete -c $progname -n $$condition -s q -l quiet -d 'Show less information' - complete -c $progname -n $$condition -s s -l search -r -d 'Search packages for regexp' - end - - # Query options - complete -c $progname -n $query -s c -l changelog -d 'View the change log of PACKAGE' - complete -c $progname -n $query -s d -l deps -d 'List only non-explicit packages (dependencies)' - complete -c $progname -n $query -s e -l explicit -d 'List only explicitly installed packages' - complete -c $progname -n $query -s k -l check -d 'Check if all files owned by PACKAGE are present' - complete -c $progname -n $query -s l -l list -d 'List all files owned by PACKAGE' - complete -c $progname -n $query -s m -l foreign -d 'List all packages not in the database' - complete -c $progname -n $query -s o -l owns -r -d 'Search for the package that owns FILE' -xa '' - complete -c $progname -n $query -s p -l file -d 'Apply the query to a package file, not package' -xa '' - complete -c $progname -n $query -s t -l unrequired -d 'List only unrequired packages' - complete -c $progname -n $query -s u -l upgrades -d 'List only out-of-date packages' - complete -c $progname -n "$query; and $argument" -d 'Installed package' -xa $listinstalled - - # Remove options - complete -c $progname -n $remove -s c -l cascade -d 'Also remove packages depending on PACKAGE' - complete -c $progname -n $remove -s n -l nosave -d 'Ignore file backup designations' - complete -c $progname -n $remove -s s -l recursive -d 'Also remove dependencies of PACKAGE' - complete -c $progname -n $remove -s u -l unneeded -d 'Only remove targets not required by PACKAGE' - complete -c $progname -n "$remove; and $argument" -d 'Installed package' -xa $listinstalled - - # Sync options - complete -c $progname -n $sync -s c -l clean -d 'Remove [all] packages from cache' - complete -c $progname -n $sync -s l -l list -xa "$listrepos" -d 'List all packages in REPOSITORY' - complete -c $progname -n $sync -s u -l sysupgrade -d 'Upgrade all packages that are out of date' - complete -c $progname -n $sync -s w -l downloadonly -d 'Only download the target packages' - complete -c $progname -n $sync -s y -l refresh -d 'Download fresh copy of the package list' - complete -c $progname -n "$argument; and $sync" -xa "$listall $listgroups" - - # Upgrade options - complete -c $progname -n "$upgrade; and $argument" -xa '(__fish_complete_suffix pkg.tar.xz)' -d 'Package file' - complete -c $progname -n "$upgrade; and $argument" -xa '(__fish_complete_suffix pkg.tar.gz)' -d 'Package file' -end -