fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerMerge pull request #1152274ce965f3

master
6.1 KiB144 linesraw
1# Completions for the `apt` command
2
3# macOS has a /usr/bin/apt that is something else entirely:
4# (apt - Returns the path to a Java home directory from the current user's settings)
5if [ "$(uname -s)" = Darwin -a "$(command -s apt)" = /usr/bin/apt ]
6    exit 1
7end
8
9set -l all_subcmds update upgrade full-upgrade search list install show remove edit-sources purge changelog autoremove autopurge depends rdepends
10set -l pkg_subcmds install upgrade full-upgrade show search purge changelog policy depends rdepends autoremove autopurge
11set -l installed_pkg_subcmds remove
12set -l handle_file_pkg_subcmds install
13
14function __fish_apt_subcommand -V all_subcmds
15    set -l subcommand $argv[1]
16    set -e argv[1]
17    complete -f -c apt -n __fish_is_first_token -a $subcommand $argv
18end
19
20function __fish_apt_option
21    set -l subcommand $argv[1]
22    set -e argv[1]
23    complete -f -c apt -n "__fish_seen_subcommand_from $subcommand" $argv
24end
25
26function __fish_apt_list_repos
27    # A single `string` invocation can't read from multiple files and so we use `cat`
28    # but /etc/apt/sources.list.d/ may or may not contain any files so using a fish
29    # wildcard glob may complain loudly if no files match the pattern so we use `find`.
30    # The trailing `sort -u` is largely decorative.
31    cat (find /etc/apt/sources.list /etc/apt/sources.list.d/ -name "*.list") | string replace -rf '^\s*deb *(?:\[.*?\])? (?:[^ ]+) +([^ ]+) .*' '$1' | sort -u
32end
33
34complete -c apt -f
35
36# We use -k to keep PWD directories (from the .deb completion) after packages, so we need to sort the packages
37complete -k -c apt -n "__fish_seen_subcommand_from $handle_file_pkg_subcmds" -kxa '(__fish_complete_suffix .deb)'
38complete -k -c apt -n "__fish_seen_subcommand_from $pkg_subcmds" -kxa '(__fish_print_apt_packages | sort)'
39complete -c apt -n "__fish_seen_subcommand_from $installed_pkg_subcmds" -kxa '(__fish_print_apt_packages --installed | sort)'
40
41complete -c apt -n "__fish_seen_subcommand_from install" -l no-install-recommends -d 'Do not install recommended packages'
42complete -c apt -n "__fish_seen_subcommand_from install" -l no-install-suggests -d 'Do not install suggested packages'
43complete -c apt -n "__fish_seen_subcommand_from install" -s d -l download-only -d 'Download Only'
44complete -c apt -n "__fish_seen_subcommand_from install" -s f -l fix-broken -d 'Correct broken dependencies'
45complete -c apt -n "__fish_seen_subcommand_from install" -s m -l fix-missing -d 'Ignore missing packages'
46complete -c apt -n "__fish_seen_subcommand_from install" -l no-download -d 'Disable downloading packages'
47complete -c apt -n "__fish_seen_subcommand_from install" -s q -l quiet -d 'Quiet mode'
48complete -c apt -n "__fish_seen_subcommand_from install" -s s -l simulate -l just-print -l dry-run -l recon -l no-act -d 'Perform a simulation'
49complete -c apt -n "__fish_seen_subcommand_from install" -s y -l yes -l assume-yes -d 'Automatic yes to prompts'
50complete -c apt -n "__fish_seen_subcommand_from install" -l assume-no -d 'Automatic no to prompts'
51complete -c apt -n "__fish_seen_subcommand_from install" -l install-recommends -d 'Install recommended packages'
52complete -c apt -n "__fish_seen_subcommand_from install" -l install-suggests -d 'Install suggested packages'
53# This advanced flag is the safest way to upgrade packages that otherwise would have been kept back
54complete -c apt -n "__fish_seen_subcommand_from upgrade" -l with-new-pkgs
55
56# Support flags
57complete -f -c apt -s h -l help -d 'Display help'
58complete -f -c apt -s v -l version -d 'Display version and exit'
59
60# General options
61complete -x -c apt -s o -l option -d 'Set a configuration option'
62complete -r -c apt -s c -l config-file -d 'Configuration file'
63complete -x -c apt -s t -d 'Install from specific repository' -x -a '(__fish_apt_list_repos)'
64
65# List
66__fish_apt_subcommand list -d 'List packages'
67__fish_apt_option list -l installed -d 'Installed packages'
68__fish_apt_option list -l manual-installed -d 'Manually installed packages'
69__fish_apt_option list -l upgradable -d 'Upgradable packages'
70__fish_apt_option list -s a -l all-versions -d 'Show all versions of any package'
71__fish_apt_option list -s v -l verbose -d 'Verbose output'
72
73# Search
74__fish_apt_subcommand search -r -d 'Search for packages'
75
76# Show
77__fish_apt_subcommand show -r -d 'Show package information'
78
79# Showsrc
80__fish_apt_subcommand showsrc -r -d 'Show source package information'
81
82# Source
83__fish_apt_subcommand source -r -d 'Download source package'
84
85# Install
86__fish_apt_subcommand install -r -d 'Install packages'
87__fish_apt_option install -l reinstall -d 'Reinstall package'
88
89# Reinstall
90__fish_apt_subcommand reinstall -r -d 'Reinstall packages'
91
92# Remove
93__fish_apt_subcommand remove -x -d 'Remove packages'
94
95# Edit sources
96__fish_apt_subcommand edit-sources -d 'Edit sources list'
97
98# Update
99__fish_apt_subcommand update -x -d 'Update package list'
100
101# Upgrade
102__fish_apt_subcommand upgrade -r -d 'Upgrade packages'
103
104# Full Upgrade
105__fish_apt_subcommand full-upgrade -r -d 'Upgrade packages, removing others when needed'
106__fish_apt_subcommand dist-upgrade -r -d 'Upgrade packages, removing others when needed'
107
108# Purge
109__fish_apt_subcommand purge -x -d 'Remove packages and delete their config files'
110
111# Changelog
112__fish_apt_subcommand changelog -r -d 'Download and display package changelog'
113
114# Autoremove
115__fish_apt_subcommand autoremove -d 'Remove packages no longer needed as dependencies'
116
117# Autopurge
118__fish_apt_subcommand autopurge -d 'Remove packages no longer needed as dependencies and delete their config files'
119
120# Clean
121__fish_apt_subcommand clean -d 'Remove downloaded packages from cache'
122
123# Autoclean
124__fish_apt_subcommand autoclean -d 'Remove obsolete packages from cache'
125
126# Policy
127__fish_apt_subcommand policy -x -d 'Display source or package priorities'
128
129# Depends
130__fish_apt_subcommand depends -r -d 'List package dependencies'
131
132# Rdepends
133__fish_apt_subcommand rdepends -r -d 'List package reverse dependencies'
134
135# Download
136__fish_apt_subcommand download -x -d 'Download packages'
137
138# Build-dep
139__fish_apt_subcommand build-dep -x -d 'Install packages needed to build the given package'
140
141# Help
142__fish_apt_subcommand help -d 'Print help page'
143
144functions -e __fish_apt_subcommand __fish_apt_option