| 1 |
#compdef pacstrap |
| 2 |
|
| 3 |
_pacstrap_args=( |
| 4 |
'-h[display help]' |
| 5 |
) |
| 6 |
|
| 7 |
_pacstrap_args_nonh=( |
| 8 |
'-C[Use an alternate config file for pacman]:config file:_files -/' |
| 9 |
'-c[Use the package cache on the host, rather than the target]' |
| 10 |
'-D[Skip pacman dependency checks]' |
| 11 |
'-G[Avoid copying the host pacman keyring to the target]' |
| 12 |
'-i[Prompt for package confirmation when needed (run interactively)]' |
| 13 |
'-K[Initialize an empty pacman keyring in the target (implies -G)]' |
| 14 |
'-M[Avoid copying the host mirrorlist to the target]' |
| 15 |
'-N[Run in unshare mode as a regular user]' |
| 16 |
'-P[Copy the host pacman config to the target]' |
| 17 |
'-U[Use pacman -U to install packages]' |
| 18 |
) |
| 19 |
|
| 20 |
|
| 21 |
# builds command for invoking pacman in a _call_program command - extracts |
| 22 |
# relevant options already specified (config file, etc) |
| 23 |
# $cmd must be declared by calling function |
| 24 |
_pacman_get_command() { |
| 25 |
# this is mostly nicked from _perforce |
| 26 |
cmd=( "pacman" "2>/dev/null") |
| 27 |
integer i |
| 28 |
for (( i = 2; i < CURRENT - 1; i++ )); do |
| 29 |
if [[ ${words[i]} = "--config" || ${words[i]} = "--root" ]]; then |
| 30 |
cmd+=( ${words[i,i+1]} ) |
| 31 |
fi |
| 32 |
done |
| 33 |
} |
| 34 |
|
| 35 |
# provides completions for packages available from repositories |
| 36 |
# these can be specified as either 'package' or 'repository/package' |
| 37 |
_pacman_completions_all_packages() { |
| 38 |
local -a cmd packages repositories packages_long |
| 39 |
_pacman_get_command |
| 40 |
|
| 41 |
if compset -P1 '*/*'; then |
| 42 |
packages=( $(_call_program packages $cmd[@] -Sql ${words[CURRENT]%/*}) ) |
| 43 |
typeset -U packages |
| 44 |
_wanted repo_packages expl "repository/package" compadd ${(@)packages} |
| 45 |
else |
| 46 |
packages=( $(_call_program packages $cmd[@] -Sql) ) |
| 47 |
typeset -U packages |
| 48 |
_wanted packages expl "packages" compadd - "${(@)packages}" |
| 49 |
|
| 50 |
repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options}) |
| 51 |
typeset -U repositories |
| 52 |
_wanted repo_packages expl "repository/package" compadd -S "/" $repositories |
| 53 |
fi |
| 54 |
} |
| 55 |
|
| 56 |
_pacstrap_none(){ |
| 57 |
_arguments -s : \ |
| 58 |
"$_pacstrap_args[@]" \ |
| 59 |
"$_longopts[@]" \ |
| 60 |
} |
| 61 |
|
| 62 |
_longopts=( '--help[display help]' ) |
| 63 |
|
| 64 |
_pacstrap(){ |
| 65 |
if [[ -z ${(M)words:#--help} && -z ${(M)words:#-h} ]]; then |
| 66 |
case $words[CURRENT] in |
| 67 |
-c*|-d*|-i*) |
| 68 |
_arguments -s "$_pacstrap_args_nonh[@]" |
| 69 |
;; |
| 70 |
-*) |
| 71 |
_arguments -s : \ |
| 72 |
"$_pacstrap_args[@]" \ |
| 73 |
"$_pacstrap_args_nonh[@]" \ |
| 74 |
"$_longopts[@]" |
| 75 |
;; |
| 76 |
--*) |
| 77 |
_arguments -s : \ |
| 78 |
"$_longopts[@]" |
| 79 |
;; |
| 80 |
*) |
| 81 |
_arguments -s : \ |
| 82 |
"$_pacstrap_args[@]" \ |
| 83 |
"$_pacstrap_args_nonh[@]" \ |
| 84 |
"$_longopts[@]" \ |
| 85 |
":*:_path_files -/" \ |
| 86 |
":*:_pacman_completions_all_packages" |
| 87 |
;; |
| 88 |
esac |
| 89 |
else |
| 90 |
return 1 |
| 91 |
fi |
| 92 |
} |
| 93 |
|
| 94 |
_install_scripts(){ |
| 95 |
case "$service" in |
| 96 |
pacstrap) |
| 97 |
_pacstrap "$@";; |
| 98 |
esac |
| 99 |
} |
| 100 |
|
| 101 |
_install_scripts "$@" |