2015-04-08 16:49:58 +00:00
|
|
|
# Completions for the `apt` command
|
|
|
|
|
2022-10-29 18:28:37 +00:00
|
|
|
# macOS has a /usr/bin/apt that is something else entirely:
|
|
|
|
# (apt - Returns the path to a Java home directory from the current user's settings)
|
2022-10-30 10:25:52 +00:00
|
|
|
if [ "$(uname -s)" = Darwin -a "$(command -s apt)" = /usr/bin/apt ]
|
2022-10-29 18:28:37 +00:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
2018-05-22 22:29:12 +00:00
|
|
|
set -l all_subcmds update upgrade full-upgrade search list install show remove edit-sources purge changelog autoremove depends rdepends
|
2020-06-08 15:43:07 +00:00
|
|
|
set -l pkg_subcmds install upgrade full-upgrade show search purge changelog policy depends rdepends autoremove
|
2018-07-02 16:40:01 +00:00
|
|
|
set -l installed_pkg_subcmds remove
|
2020-01-29 03:49:51 +00:00
|
|
|
set -l handle_file_pkg_subcmds install
|
2018-05-20 19:07:56 +00:00
|
|
|
|
2020-12-16 17:31:51 +00:00
|
|
|
function __fish_apt_subcommand -V all_subcmds
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l subcommand $argv[1]
|
2017-08-21 20:30:10 +00:00
|
|
|
set -e argv[1]
|
2018-05-22 22:29:12 +00:00
|
|
|
complete -f -c apt -n "not __fish_seen_subcommand_from $all_subcmds" -a $subcommand $argv
|
2017-08-21 20:30:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function __fish_apt_option
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l subcommand $argv[1]
|
2017-08-21 20:30:10 +00:00
|
|
|
set -e argv[1]
|
2018-05-20 19:07:56 +00:00
|
|
|
complete -f -c apt -n "__fish_seen_subcommand_from $subcommand" $argv
|
2017-08-21 20:30:10 +00:00
|
|
|
end
|
|
|
|
|
2020-12-05 16:43:51 +00: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 03:49:51 +00:00
|
|
|
complete -c apt -f
|
|
|
|
|
2021-08-18 05:17:15 +00: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 03:49:51 +00:00
|
|
|
complete -k -c apt -n "__fish_seen_subcommand_from $handle_file_pkg_subcmds" -a '(__fish_complete_suffix .deb)'
|
2015-04-08 16:49:58 +00:00
|
|
|
|
2020-09-04 02:47:12 +00:00
|
|
|
complete -c apt -n "__fish_seen_subcommand_from install" -l no-install-recommends
|
2020-09-23 02:52:47 +00: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 02:47:12 +00:00
|
|
|
|
2015-04-08 16:49:58 +00:00
|
|
|
# Support flags
|
2020-01-29 03:49:51 +00: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-08 16:49:58 +00:00
|
|
|
|
|
|
|
# General options
|
2020-01-29 03:49:51 +00: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-05 16:43:51 +00:00
|
|
|
complete -x -c apt -s t -d 'Install from specific repository' -x -a '(__fish_apt_list_repos)'
|
2015-04-08 16:49:58 +00:00
|
|
|
|
|
|
|
# List
|
2019-05-05 10:53:09 +00: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-08 16:49:58 +00:00
|
|
|
|
|
|
|
# Search
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand search -r -d 'Search for packages'
|
2015-04-08 16:49:58 +00:00
|
|
|
|
|
|
|
# Search
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand show -r -d 'Show package information'
|
2015-04-08 16:49:58 +00:00
|
|
|
|
|
|
|
# Install
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand install -r -d 'Install packages'
|
2019-11-09 00:07:23 +00:00
|
|
|
__fish_apt_option install -l reinstall -d 'Reinstall package'
|
2015-04-08 16:49:58 +00:00
|
|
|
|
|
|
|
# Remove
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand remove -r -d 'Remove packages'
|
2015-04-08 16:49:58 +00:00
|
|
|
|
|
|
|
# Edit sources
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand edit-sources -d 'Edit sources list'
|
2015-04-08 16:49:58 +00:00
|
|
|
|
|
|
|
# Update
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand update -x -d 'Update package list'
|
2015-04-08 16:49:58 +00:00
|
|
|
|
|
|
|
# Upgrade
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand upgrade -r -d 'Upgrade packages'
|
2015-04-08 16:49:58 +00:00
|
|
|
|
|
|
|
# Full Upgrade
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand full-upgrade -r -d 'Upgrade packages, removing others when needed'
|
2016-05-31 22:56:22 +00:00
|
|
|
|
|
|
|
# Purge
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand purge -x -d 'Remove packages and delete their config files'
|
2017-01-03 18:43:55 +00:00
|
|
|
|
|
|
|
# Changelog
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand changelog -r -d 'Download and display package changelog'
|
2017-01-24 18:55:42 +00:00
|
|
|
|
|
|
|
# Autoremove
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand autoremove -d 'Remove packages no longer needed as dependencies'
|
2018-01-13 03:03:36 +00:00
|
|
|
|
|
|
|
# Policy
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand policy -x -d 'Display source or package priorities'
|
2018-02-19 10:45:35 +00:00
|
|
|
|
|
|
|
# Depends
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand depends -r -d 'List package dependencies'
|
2018-02-19 10:45:35 +00:00
|
|
|
|
|
|
|
# Rdepends
|
2019-05-05 10:53:09 +00:00
|
|
|
__fish_apt_subcommand rdepends -r -d 'List package reverse dependencies'
|
2020-01-29 03:49:51 +00:00
|
|
|
|
|
|
|
functions -e __fish_apt_subcommand __fish_apt_option
|