summarylogtreecommitdiffstats
path: root/_pamac
blob: f070ebe557e7158cc542cac4ea81101836775d89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#compdef pamac

# copy this file to /usr/share/zsh/site-functions/_pamac

typeset -A opt_args
setopt extendedglob

# provides completions for package groups
_pamac_completions_all_groups() {
    local -a cmd groups
    groups=( $(_call_program groups pacman -Sg) )
    typeset -U groups

    if [[ ${words[CURRENT-1]} == '--ignoregroup' ]]; then
        _sequence compadd -S ',' "$@" -a groups
    else
        compadd "$@" -a groups
    fi
}

# provides completions for packages available from repositories
# these can be specified as either 'package' or 'repository/package'
_pamac_completions_all_packages() {
    local -a seq sep cmd packages repositories packages_long

    if [[ ${words[CURRENT-1]} == '--ignore' ]]; then
        seq='_sequence'
        sep=(-S ',')
    else
        seq=
        sep=()
    fi

    if compset -P1 '*/*'; then
        packages=( $(_call_program packages pacman -Sql ${words[CURRENT]%/*}) )
        typeset -U packages
        ${seq} _wanted repo_packages expl "repository/package" compadd ${sep[@]} ${(@)packages}
    else
        packages=( $(_call_program packages pamac search -q ${words[CURRENT]}) )
        typeset -U packages
        ${seq} _wanted packages expl "packages" compadd ${sep[@]} - "${(@)packages}"

        repositories=($(pacman-conf --repo-list))
        typeset -U repositories
        _wanted repo_packages expl "repository/package" compadd -S "/" $repositories
    fi
}

# provides completions for package groups
_pamac_completions_installed_groups() {
    local -a cmd groups
    groups=(${(o)${(f)"$(_call_program groups pacman -Qg)"}% *})
    typeset -U groups
    compadd "$@" -a groups
}

# provides completions for installed packages
_pamac_completions_installed_packages() {
    local -a cmd packages packages_long
    packages_long=(/var/lib/pacman/local/*(/))
    packages=( ${${packages_long#/var/lib/pacman/local/}%-*-*} )
    compadd "$@" -a packages
}

_pamac_completions_all_packages_and_groups() {
    _alternative : \
        'pkgs:packages:_pamac_completions_all_packages' \
        'grps:groups:_pamac_completions_all_groups'
}

_pamac_completions_installed_packages_and_groups() {
    _alternative : \
        'pkgs:installed packages:_pamac_completions_installed_packages' \
        'grps:installed groups:_pamac_completions_installed_groups'
}
_pamac_completions_all_packages_groups_and_local() {
    _alternative : \
        'pkgs:packages:_pamac_completions_all_packages' \
        'grps:groups:_pamac_completions_all_groups' \
        'locl:package files:_path_files -g "*.pkg.tar(|.z|.gz|.bz|.bz2|.lrz|.lz|.lz4|.lzop|.xz|.lzma|.zst)"'
}


# provides completions for repository names
_pamac_completions_repositories() {
    local -a cmd repositories
    repositories=($(pacman-conf --repo-list))
    # Uniq the array
    typeset -U repositories
    compadd "$@" -a repositories
}


local -a pamac_commands
pamac_commands=('clean' 'checkupdates' 'update' 'upgrade' 'search' 'info' 'list' 'install' 'reinstall' 'clone' 'build' 'remove')

_pamac_commands() {
    local -a commands_descr
    commands_descr=(
        "build:build packages from AUR and install them with their dependencies"
        "checkupdates:safely check for updates without modifiying the databases"
        "clean:clean packages cache or build files"
        "clone:clone or sync packages build files from AUR"
        "info:display package details, multiple packages can be specified"
        "install:install packages from repositories, path or url"
        "list:list packages, groups, repositories or files"
        "reinstall:reinstall packages"
        "remove:remove packages"
        "search:search for packages or files, multiple search terms can be specified"
        "update:upgrade your system"
        "upgrade:upgrade your system"
    )
    _describe -t commands 'command' commands_descr
}


_pamac_command_clean() {
    _arguments : \
        "(1 * -)--help[show help for command]" \
        "(-k --keep)"{-k,--keep}"[specify how many versions of each package are kept in the cache directory]:number:_values number 0 1 2 3 4 5 6 7 8 9" \
        "(-u --uninstalled)"{-u,--uninstalled}"[only target uninstalled packages]" \
        "(-b --build-files)"{-b,--build-files}"[remove all build files, the build directory is the one specified in pamac.conf]" \
        "(-d --dry-run)"{-d,--dry-run}"[do not remove files, only find candidate packages]" \
        "(-v --verbose)"{-v,--verbose}"[also display all files names]" \
        "(--no-confirm)--no-confirm[bypass any and all confirmation messages]"
}

_pamac_command_checkupdates() {
    _arguments : \
        "(1 * -)--help[show help for command]" \
        "(-a --aur)"{-a,--aur}"[also check updates in AUR]" \
        "(--devel)--devel[also check development packages updates (use with --aur)]" \
        "(-q --quiet)"{-q,--quiet}"[only print one line per update]" \
        "(--builddir)--builddir[build directory (use with --devel), if no directory is given the one specified in pamac.conf file is used]:dir:_path_files -/"
}

_pamac_command_update() {
    _arguments : \
        "(1 * -)--help[show help for command]" \
        "(-a --aur)"{-a,--aur}"[also upgrade packages installed from AUR]" \
        "(--devel)--devel[also upgrade development packages (use with --aur)]" \
        "(--builddir)--builddir[build directory (use with --aur), if no directory is given the one specified in pamac.conf file is used]:dir:_path_files" \
        "(--force-refresh)--force-refresh[force the refresh of the databases]" \
        "(--enable-downgrade)--enable-downgrade[enable package downgrades]" \
        "(--ignore)--ignore[ignore a package upgrade, multiple packages can be specified by separating them with a comma]:packages:_pamac_completions_installed_packages" \
        "(--overwrite)--overwrite[overwrite conflicting files, multiple patterns can be specified by separating them with a comma]:files:_files" \
        "(--no-confirm)--no-confirm[bypass any and all confirmation messages]"
}

_pamac_command_upgrade() {
    _pamac_command_update
}

_pamac_command_search() {
    _arguments : \
        "(1 * -)--help[show help for command]" \
        "(-a --aur)"{-a,--aur}"[also check updates in AUR]" \
        "(-f --files)"{-f,--files}"[search for packages which own the given filenames (filenames can be partial)]:files:_files" \
        "*:file:_files"
 }

_pamac_command_info() {
    _arguments : \
        "(1 * -)--help[show help for command]" \
        "(-a --aur)"{-a,--aur}"[also search in AUR]" \
        "*:packages:_pamac_completions_all_packages"
}

_pamac_command_list() {
    _arguments : \
        "(1 * -)--help[show help for command]" \
        "(-i --installed)"{-i,--installed}"[list installed packages]" \
        "(-o --orphans)"{-o,--orphans}"[list packages that were installed as dependencies but are no longer required by any installed package]" \
        "(-m --foreign)"{-m,--foreign}"[list packages that were not found in the repositories]" \
        "(-g --groups)"{-g,--groups}"[list all packages that are members of the given groups, if no group is given list all groups]:groups:_pamac_completions_all_groups" \
        "(-r --repos)"{-r,--repos}"[list all packages available in the given repos, if no repo is given list all repos]:repos:_pamac_completions_repositories" \
        "(-f --files)"{-f,--files}"[list files owned by the given packages]:packages:_pamac_completions_all_packages"
}

_pamac_command_install() {
    _arguments : \
        "(1 * -)--help[show help for command]" \
        "(--ignore)--ignore[ignore a package upgrade, multiple packages can be specified by separating them with a comma]:packages:_pamac_completions_all_packages" \
        "(--overwrite)--overwrite[overwrite conflicting files, multiple patterns can be specified by separating them with a comma]:glob:_files" \
        "(--no-confirm)--no-confirm[bypass any and all confirmation messages]" \
        "*:packages:_pamac_completions_all_packages_groups_and_local"
}

_pamac_command_reinstall() {
    _arguments : \
        "(1 * -)--help[show help for command]" \
        "(--overwrite)--overwrite[overwrite conflicting files, multiple patterns can be specified by separating them with a comma]:glob:_files" \
        "(--no-confirm)--no-confirm[bypass any and all confirmation messages]" \
        "*:packages:_pamac_completions_installed_packages"
}


_pamac_command_clone() {
    _arguments : \
        "(1 * -)--help[show help for command]" \
        "(--builddir)--builddir[build directory, if no directory is given the one specified in pamac.conf file is used]:dir:_path_files -/" \
        "(-r --recurse)"{-r,--recurse}"[also clone needed dependencies]" \
        "(--overwrite)--overwrite[overwrite existing files]" \
        "*:packages:_pamac_completions_all_packages"
}

_pamac_command_build() {
    _arguments : \
        "(1 * -)--help[show help for command]" \
        "(--builddir)--builddir[build directory, if no directory is given the one specified in pamac.conf file is used]:dir:_path_files -/" \
        "(-k --keep)"{-k,--keep}"[keep built packages in cache after installation]" \
        "(--no-clone)--no-clone[do not clone build files from AUR, only use local files]" \
        "(--no-confirm)--no-confirm[bypass any and all confirmation messages]" \
        "*:packages:_pamac_completions_all_packages"
}

_pamac_command_remove() {
    _arguments : \
        "(1 * -)--help[show help for command]" \
        "(-o --orphans)"{-o,--orphans}"[remove dependencies that are not required by other packages, if this option is used without package name remove all orphans]" \
        "(--no-confirm)--no-confirm[bypass any and all confirmation messages]" \
        "*:packages:_pamac_completions_installed_packages_and_groups"
}


# main dispatcher
_arguments -C : \
    "(1 * -)--version[print pamac version]" \
    "(1 * -)--help[show help for command]:command:_values command $pamac_commands" \
    "(-)1: :_pamac_commands" \
    "(-)*:: :->args"

if [ "$state" = "args" ]; then
    (( ${pamac_commands[(I)${line[1]}]} )) && _pamac_command_$line[1]
fi