2015-04-09 00:49:58 +08:00
|
|
|
# Completions for the `apt` command
|
|
|
|
|
2018-05-23 06:29:12 +08:00
|
|
|
set -l all_subcmds update upgrade full-upgrade search list install show remove edit-sources purge changelog autoremove depends rdepends
|
2020-06-08 23:43:07 +08:00
|
|
|
set -l pkg_subcmds install upgrade full-upgrade show search purge changelog policy depends rdepends autoremove
|
2018-07-03 00:40:01 +08:00
|
|
|
set -l installed_pkg_subcmds remove
|
2020-01-29 11:49:51 +08:00
|
|
|
set -l handle_file_pkg_subcmds install
|
2018-05-21 03:07:56 +08:00
|
|
|
|
2020-12-17 01:31:51 +08:00
|
|
|
function __fish_apt_subcommand -V all_subcmds
|
2020-05-15 13:56:06 +08:00
|
|
|
set -l subcommand $argv[1]
|
2017-08-22 04:30:10 +08:00
|
|
|
set -e argv[1]
|
2018-05-23 06:29:12 +08:00
|
|
|
complete -f -c apt -n "not __fish_seen_subcommand_from $all_subcmds" -a $subcommand $argv
|
2017-08-22 04:30:10 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function __fish_apt_option
|
2020-05-15 13:56:06 +08:00
|
|
|
set -l subcommand $argv[1]
|
2017-08-22 04:30:10 +08:00
|
|
|
set -e argv[1]
|
2018-05-21 03:07:56 +08:00
|
|
|
complete -f -c apt -n "__fish_seen_subcommand_from $subcommand" $argv
|
2017-08-22 04:30:10 +08:00
|
|
|
end
|
|
|
|
|
2020-12-06 00:43:51 +08:00
|
|
|
function __fish_apt_list_repos
|
|
|
|
# A single `string` invocation can't read from multiple files and so we use `cat`
|
|
|
|
# but /etc/apt/sources.list.d/ may or may not contain any files so using a fish
|
|
|
|
# wildcard glob may complain loudly if no files match the pattern so we use `find`.
|
|
|
|
# The trailing `sort -u` is largely decorative.
|
|
|
|
cat (find /etc/apt/sources.list /etc/apt/sources.list.d/ -name "*.list") | string replace -rf '^\s*deb *(?:\[.*?\])? (?:[^ ]+) +([^ ]+) .*' '$1' | sort -u
|
|
|
|
end
|
|
|
|
|
2020-01-29 11:49:51 +08:00
|
|
|
complete -c apt -f
|
|
|
|
|
2021-08-18 13:17:15 +08:00
|
|
|
complete -k -c apt -n "__fish_seen_subcommand_from $pkg_subcmds" -a '(__fish_print_apt_packages | string match -re -- "(?:\\b|_)"(commandline -ct | string escape --style=regex) | head -n 250 | sort)'
|
|
|
|
complete -c apt -n "__fish_seen_subcommand_from $installed_pkg_subcmds" -a '(__fish_print_apt_packages --installed | string match -re -- "(?:\\b|_)"(commandline -ct | string escape --style=regex) | head -n 250)'
|
2020-01-29 11:49:51 +08:00
|
|
|
complete -k -c apt -n "__fish_seen_subcommand_from $handle_file_pkg_subcmds" -a '(__fish_complete_suffix .deb)'
|
2015-04-09 00:49:58 +08:00
|
|
|
|
2020-09-04 10:47:12 +08:00
|
|
|
complete -c apt -n "__fish_seen_subcommand_from install" -l no-install-recommends
|
2020-09-23 10:52:47 +08:00
|
|
|
# This advanced flag is the safest way to upgrade packages that otherwise would have been kept back
|
|
|
|
complete -c apt -n "__fish_seen_subcommand_from upgrade" -l with-new-pkgs
|
2020-09-04 10:47:12 +08:00
|
|
|
|
2015-04-09 00:49:58 +08:00
|
|
|
# Support flags
|
2020-01-29 11:49:51 +08:00
|
|
|
complete -f -c apt -s h -l help -d 'Display help'
|
|
|
|
complete -f -c apt -s v -l version -d 'Display version and exit'
|
2015-04-09 00:49:58 +08:00
|
|
|
|
|
|
|
# General options
|
2020-01-29 11:49:51 +08:00
|
|
|
complete -x -c apt -s o -l option -d 'Set a configuration option'
|
|
|
|
complete -r -c apt -s c -l config-file -d 'Configuration file'
|
2020-12-06 00:43:51 +08:00
|
|
|
complete -x -c apt -s t -d 'Install from specific repository' -x -a '(__fish_apt_list_repos)'
|
2015-04-09 00:49:58 +08:00
|
|
|
|
|
|
|
# List
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand list -d 'List packages'
|
|
|
|
__fish_apt_option list -l installed -d 'Installed packages'
|
|
|
|
__fish_apt_option list -l upgradable -d 'Upgradable packages'
|
|
|
|
__fish_apt_option list -l all-versions -d 'Show all versions of any package'
|
2015-04-09 00:49:58 +08:00
|
|
|
|
|
|
|
# Search
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand search -r -d 'Search for packages'
|
2015-04-09 00:49:58 +08:00
|
|
|
|
|
|
|
# Search
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand show -r -d 'Show package information'
|
2015-04-09 00:49:58 +08:00
|
|
|
|
|
|
|
# Install
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand install -r -d 'Install packages'
|
2019-11-09 08:07:23 +08:00
|
|
|
__fish_apt_option install -l reinstall -d 'Reinstall package'
|
2015-04-09 00:49:58 +08:00
|
|
|
|
|
|
|
# Remove
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand remove -r -d 'Remove packages'
|
2015-04-09 00:49:58 +08:00
|
|
|
|
|
|
|
# Edit sources
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand edit-sources -d 'Edit sources list'
|
2015-04-09 00:49:58 +08:00
|
|
|
|
|
|
|
# Update
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand update -x -d 'Update package list'
|
2015-04-09 00:49:58 +08:00
|
|
|
|
|
|
|
# Upgrade
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand upgrade -r -d 'Upgrade packages'
|
2015-04-09 00:49:58 +08:00
|
|
|
|
|
|
|
# Full Upgrade
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand full-upgrade -r -d 'Upgrade packages, removing others when needed'
|
2016-06-01 06:56:22 +08:00
|
|
|
|
|
|
|
# Purge
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand purge -x -d 'Remove packages and delete their config files'
|
2017-01-04 02:43:55 +08:00
|
|
|
|
|
|
|
# Changelog
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand changelog -r -d 'Download and display package changelog'
|
2017-01-25 02:55:42 +08:00
|
|
|
|
|
|
|
# Autoremove
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand autoremove -d 'Remove packages no longer needed as dependencies'
|
2018-01-13 11:03:36 +08:00
|
|
|
|
|
|
|
# Policy
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand policy -x -d 'Display source or package priorities'
|
2018-02-19 18:45:35 +08:00
|
|
|
|
|
|
|
# Depends
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand depends -r -d 'List package dependencies'
|
2018-02-19 18:45:35 +08:00
|
|
|
|
|
|
|
# Rdepends
|
2019-05-05 18:53:09 +08:00
|
|
|
__fish_apt_subcommand rdepends -r -d 'List package reverse dependencies'
|
2020-01-29 11:49:51 +08:00
|
|
|
|
|
|
|
functions -e __fish_apt_subcommand __fish_apt_option
|