zsh-completion 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. #compdef yay
  2. typeset -A opt_args
  3. setopt extendedglob
  4. # options for passing to _arguments: main pacman commands
  5. _pacman_opts_commands=(
  6. {-D,--database}'[Modify database]'
  7. {-F,--files}'[Query the files database]'
  8. {-G,--getpkgbuild}'[Get PKGBUILD from ABS or AUR]'
  9. {-Q,--query}'[Query the package database]'
  10. {-R,--remove}'[Remove a package from the system]'
  11. {-P,--print}'[Print yay information]'
  12. {-S,--sync}'[Synchronize packages]'
  13. {-T,--deptest}'[Check if dependencies are installed]'
  14. {-U,--upgrade}'[Upgrade a package]'
  15. {-Y,--yay}'[Yay specific options]'
  16. {-V,--version}'[Display version and exit]'
  17. '(-h --help)'{-h,--help}'[Display usage]'
  18. )
  19. # options for passing to _arguments: options common to all commands
  20. _pacman_opts_common=(
  21. '--arch[Set an alternate architecture]'
  22. {-b,--dbpath}'[Alternate database location]:database_location:_files -/'
  23. '--color[colorize the output]:color options:(always never auto)'
  24. {-h,--help}'[Display syntax for the given operation]'
  25. {-r,--root}'[Set alternate installation root]:installation root:_files -/'
  26. {-v,--verbose}'[Be more verbose]'
  27. '--cachedir[Alternate package cache location]:cache_location:_files -/'
  28. '--config[An alternate configuration file]:config file:_files'
  29. '--confirm[Always ask for confirmation]'
  30. '--debug[Display debug messages]'
  31. '--gpgdir[Set an alternate directory for GnuPG (instead of /etc/pacman.d/gnupg)]: :_files -/'
  32. '--hookdir[Set an alternate hook location]: :_files -/'
  33. '--logfile[An alternate log file]:config file:_files'
  34. '--noconfirm[Do not ask for confirmation]'
  35. '--noprogressbar[Do not show a progress bar when downloading files]'
  36. '--noscriptlet[Do not execute the install scriptlet if one exists]'
  37. '--save[Causes config options to be saved back to the config file]'
  38. '--builddir[Directory to use for building AUR Packages]:build dir:_files -/'
  39. '--editor[Editor to use when editing PKGBUILDs]:editor:_files'
  40. '--makepkg[makepkg command to use]:makepkg:_files'
  41. '--pacman[pacman command to use]:pacman:_files'
  42. '--tar[bsdtar command to use]:tar:_files'
  43. '--git[git command to use]:git:_files'
  44. '--bottomup[Show AUR packages first]'
  45. '--topdown[Show repository packages first]'
  46. '--devel[Check -git/-svn/-hg development version]'
  47. '--nodevel[Disable development version checking]'
  48. '--afterclean[Clean package sources after successful build]'
  49. '--noafterclean[Disable package sources cleaning after successful build]'
  50. '--timeupdate[Check packages modification date and version]'
  51. '--notimeupdate[Check only package version change]'
  52. '--redownload[Always download pkgbuilds of targets]'
  53. '--redownloadall[Always download pkgbuilds of all AUR packages]'
  54. '--noredownload[Skip pkgbuild download if in cache and up to date]'
  55. '--mflags[Pass arguments to makepkg]:mflags'
  56. '--sudoloop[Loop sudo calls in the backgroud to avoid timeout]'
  57. '--nosudoloop[Do not loop sudo calls in the backgrount]'
  58. )
  59. # options for passing to _arguments: options for --upgrade commands
  60. _pacman_opts_pkgfile=(
  61. '*-d[Skip dependency checks]'
  62. '*--nodeps[Skip dependency checks]'
  63. '*--assume-installed[Add virtual package to satisfy dependencies]'
  64. '--dbonly[Only remove database entry, do not remove files]'
  65. '--force[Overwrite conflicting files]'
  66. '--needed[Do not reinstall up to date packages]'
  67. '--asdeps[mark packages as non-explicitly installed]'
  68. '--asexplicit[mark packages as explicitly installed]'
  69. {-p,--print}'[Only print the targets instead of performing the operation]'
  70. '*--ignore[Ignore a package upgrade]:package: _pacman_completions_all_packages'
  71. '*--ignoregroup[Ignore a group upgrade]:package group:_pacman_completions_all_groups'
  72. '--print-format[Specify how the targets should be printed]'
  73. '*:package file:_files -g "*.pkg.tar*~*.sig(.,@)"'
  74. )
  75. # options for passing to _arguments: subactions for --query command
  76. _pacman_opts_query_actions=(
  77. '(-Q --query)'{-Q,--query}
  78. {-g,--groups}'[View all members of a package group]:*:package groups:->query_group'
  79. {-o,--owns}'[Query the package that owns a file]:file:_files'
  80. {-p,--file}'[Package file to query]:*:package file:->query_file'
  81. {-s,--search}'[Search package names and descriptions]:*:search text:->query_search'
  82. )
  83. # options for passing to _arguments: options for --query and subcommands
  84. _pacman_opts_query_modifiers=(
  85. {-c,--changelog}'[List package changelog]'
  86. {-d,--deps}'[List packages installed as dependencies]'
  87. {-e,--explicit}'[List packages explicitly installed]'
  88. {\*-i,\*--info}'[View package information]'
  89. {\*-k,\*--check}'[Check package files]'
  90. {-l,--list}'[List package contents]'
  91. {-m,--foreign}'[List installed packages not found in sync db(s)]'
  92. {-n,--native}'[List installed packages found in sync db(s)]'
  93. {-q,--quiet}'[Show less information for query and search]'
  94. {-t,--unrequired}'[List packages not required by any package]'
  95. {-u,--upgrades}'[List packages that can be upgraded]'
  96. )
  97. # -Y
  98. _pacman_opts_yay_modifiers=(
  99. {-c,--clean}'[Remove unneeded dependencies]'
  100. '--gendb[Generates development package DB used for updating]'
  101. )
  102. # -P
  103. _pacman_opts_print_modifiers=(
  104. {-c,--complete}'[Used for completions]'
  105. {-d,--defaultconfig}'[Print default yay configuration]'
  106. {-g,--config}'[Print current yay configuration]'
  107. {-n,--numberupgrades}'[Print number of updates]'
  108. {-s,--stats}'[Display system package statistics]'
  109. {-u,--upgrades}'[Print update list]'
  110. )
  111. # options for passing to _arguments: options for --remove command
  112. _pacman_opts_remove=(
  113. {-c,--cascade}'[Remove all dependent packages]'
  114. {-d,--nodeps}'[Skip dependency checks]'
  115. '*--assume-installed[Add virtual package to satisfy dependencies]'
  116. {-n,--nosave}'[Remove protected configuration files]'
  117. {-p,--print}'[Only print the targets instead of performing the operation]'
  118. {\*-s,\*--recursive}'[Remove dependencies not required by other packages]'
  119. {-u,--unneeded}'[Remove unneeded packages]'
  120. '--dbonly[Only remove database entry, do not remove files]'
  121. '--print-format[Specify how the targets should be printed]'
  122. '*:installed package:_pacman_completions_installed_packages'
  123. )
  124. _pacman_opts_database=(
  125. '--asdeps[mark packages as non-explicitly installed]'
  126. '--asexplicit[mark packages as explicitly installed]'
  127. '*:installed package:_pacman_completions_installed_packages'
  128. )
  129. _pacman_opts_files=(
  130. {-l,--list}'[List the files owned by the queried package]:package:_pacman_completions_all_packages'
  131. {-o,--owns}'[Query the package that owns]:files:_files'
  132. {-s,--search}'[Search package file names for matching strings]:files:_files'
  133. {-x,--regex}'[Enable searching using regluar expressions]:regex:'
  134. {-y,--refresh}'[Download fresh files databases from the server]'
  135. '--machinereadable[Produce machine-readable output]'
  136. {-q,--quiet}'[Show less information for query and search]'
  137. )
  138. # options for passing to _arguments: options for --sync command
  139. _pacman_opts_sync_actions=(
  140. '(-S --sync)'{-S,--sync}
  141. {\*-c,\*--clean}'[Remove old packages from cache]:\*:clean:->sync_clean'
  142. {-g,--groups}'[View all members of a package group]:*:package groups:->sync_group'
  143. {-s,--search}'[Search package names and descriptions]:*:search text:->sync_search'
  144. '--dbonly[Only remove database entry, do not remove files]'
  145. '--needed[Do not reinstall up to date packages]'
  146. '--recursive[Reinstall all dependencies of target packages]'
  147. )
  148. # options for passing to _arguments: options for --sync command
  149. _pacman_opts_sync_modifiers=(
  150. {\*-d,\*--nodeps}'[Skip dependency checks]'
  151. '*--assume-installed[Add virtual package to satisfy dependencies]'
  152. {\*-i,\*--info}'[View package information]'
  153. {-l,--list}'[List all packages in a repository]'
  154. {-p,--print}'[Print download URIs for each package to be installed]'
  155. {-q,--quiet}'[Show less information for query and search]'
  156. {\*-u,\*--sysupgrade}'[Upgrade all out-of-date packages]'
  157. {-w,--downloadonly}'[Download packages only]'
  158. {\*-y,\*--refresh}'[Download fresh package databases]'
  159. '*--ignore[Ignore a package upgrade]:package: _pacman_completions_all_packages'
  160. '*--ignoregroup[Ignore a group upgrade]:package group:_pacman_completions_all_groups'
  161. '--asdeps[Install packages as non-explicitly installed]'
  162. '--asexplicit[Install packages as explicitly installed]'
  163. '--force[Overwrite conflicting files]'
  164. '--print-format[Specify how the targets should be printed]'
  165. )
  166. # handles --help subcommand
  167. _pacman_action_help() {
  168. _arguments -s : \
  169. "$_pacman_opts_commands[@]"
  170. }
  171. # handles cases where no subcommand has yet been given
  172. _pacman_action_none() {
  173. _arguments -s : \
  174. "$_pacman_opts_commands[@]"
  175. }
  176. # handles --query subcommand
  177. _pacman_action_query() {
  178. local context state line
  179. typeset -A opt_args
  180. case $state in
  181. query_file)
  182. _arguments -s : \
  183. "$_pacman_opts_common[@]" \
  184. "$_pacman_opts_query_modifiers[@]" \
  185. '*:package file:_files -g "*.pkg.tar*~*.sig(.,@)"'
  186. ;;
  187. query_group)
  188. _arguments -s : \
  189. "$_pacman_opts_common[@]" \
  190. "$_pacman_opts_query_modifiers[@]" \
  191. '*:groups:_pacman_completions_installed_groups'
  192. ;;
  193. query_owner)
  194. _arguments -s : \
  195. "$_pacman_opts_common[@]" \
  196. "$_pacman_opts_query_modifiers[@]" \
  197. '*:file:_files'
  198. ;;
  199. query_search)
  200. _arguments -s : \
  201. "$_pacman_opts_common[@]" \
  202. "$_pacman_opts_query_modifiers[@]" \
  203. '*:search text: '
  204. ;;
  205. *)
  206. _arguments -s : \
  207. "$_pacman_opts_common[@]" \
  208. "$_pacman_opts_query_actions[@]" \
  209. "$_pacman_opts_query_modifiers[@]" \
  210. '*:package:_pacman_completions_installed_packages'
  211. ;;
  212. esac
  213. }
  214. # handles --remove subcommand
  215. _pacman_action_remove() {
  216. _arguments -s : \
  217. '(--remove -R)'{-R,--remove} \
  218. "$_pacman_opts_common[@]" \
  219. "$_pacman_opts_remove[@]"
  220. }
  221. # handles --database subcommand
  222. _pacman_action_database() {
  223. _arguments -s : \
  224. '(--database -D)'{-D,--database} \
  225. "$_pacman_opts_common[@]" \
  226. "$_pacman_opts_database[@]"
  227. }
  228. # handles --files subcommand
  229. _pacman_action_files() {
  230. _arguments -s : \
  231. '(--files -F)'{-F,--files} \
  232. "$_pacman_opts_common[@]" \
  233. "$_pacman_opts_files[@]"
  234. }
  235. _pacman_action_deptest () {
  236. _arguments -s : \
  237. '(--deptest)-T' \
  238. "$_pacman_opts_common[@]" \
  239. ":packages:_pacman_all_packages"
  240. }
  241. # handles --sync subcommand
  242. _pacman_action_sync() {
  243. local context state line
  244. typeset -A opt_args
  245. if (( $+words[(r)--clean] )); then
  246. state=sync_clean
  247. elif (( $+words[(r)--groups] )); then
  248. state=sync_group
  249. elif (( $+words[(r)--search] )); then
  250. state=sync_search
  251. fi
  252. case $state in
  253. sync_clean)
  254. _arguments -s : \
  255. {\*-c,\*--clean}'[Remove old packages from cache]' \
  256. "$_pacman_opts_common[@]" \
  257. "$_pacman_opts_sync_modifiers[@]"
  258. ;;
  259. sync_group)
  260. _arguments -s : \
  261. "$_pacman_opts_common[@]" \
  262. "$_pacman_opts_sync_modifiers[@]" \
  263. '(-g --group)'{-g,--groups} \
  264. '*:package group:_pacman_completions_all_groups'
  265. ;;
  266. sync_search)
  267. _arguments -s : \
  268. "$_pacman_opts_common[@]" \
  269. "$_pacman_opts_sync_modifiers[@]" \
  270. '*:search text: '
  271. ;;
  272. *)
  273. _arguments -s : \
  274. "$_pacman_opts_common[@]" \
  275. "$_pacman_opts_sync_actions[@]" \
  276. "$_pacman_opts_sync_modifiers[@]" \
  277. '*:package:_pacman_completions_all_packages'
  278. ;;
  279. esac
  280. }
  281. # handles --upgrade subcommand
  282. _pacman_action_upgrade() {
  283. _arguments -s : \
  284. '(-U --upgrade)'{-U,--upgrade} \
  285. "$_pacman_opts_common[@]" \
  286. "$_pacman_opts_pkgfile[@]"
  287. }
  288. # handles --version subcommand
  289. _pacman_action_version() {
  290. # no further arguments
  291. return 0
  292. }
  293. # provides completions for package groups
  294. _pacman_completions_all_groups() {
  295. local -a cmd groups
  296. _pacman_get_command
  297. groups=( $(_call_program groups $cmd[@] -Sg) )
  298. typeset -U groups
  299. if [[ ${words[CURRENT-1]} == '--ignoregroup' ]]; then
  300. _sequence compadd -S ',' "$@" -a groups
  301. else
  302. compadd "$@" -a groups
  303. fi
  304. }
  305. # provides completions for packages available from repositories
  306. # these can be specified as either 'package' or 'repository/package'
  307. _pacman_completions_all_packages() {
  308. local -a seq sep cmd packages repositories packages_long
  309. if [[ ${words[CURRENT-1]} == '--ignore' ]]; then
  310. seq='_sequence'
  311. sep=(-S ',')
  312. else
  313. seq=
  314. sep=()
  315. fi
  316. if compset -P1 '*/*'; then
  317. packages=( $(_call_program packages yay -Pc ${words[CURRENT]%/*}) )
  318. typeset -U packages
  319. ${seq} _wanted repo_packages expl "repository/package" compadd ${sep[@]} ${(@)packages}
  320. else
  321. packages=( $(_call_program packages yay -Pc ) )
  322. typeset -U packages
  323. ${seq} _wanted packages expl "packages" compadd ${sep[@]} - "${(@)packages}"
  324. repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
  325. typeset -U repositories
  326. _wanted repo_packages expl "repository/package" compadd -S "/" $repositories
  327. fi
  328. }
  329. # provides completions for package groups
  330. _pacman_completions_installed_groups() {
  331. local -a cmd groups
  332. _pacman_get_command
  333. groups=(${(o)${(f)"$(_call_program groups $cmd[@] -Qg)"}% *})
  334. typeset -U groups
  335. compadd "$@" -a groups
  336. }
  337. # provides completions for installed packages
  338. _pacman_completions_installed_packages() {
  339. local -a cmd packages packages_long
  340. packages_long=(/var/lib/pacman/local/*(/))
  341. packages=( ${${packages_long#/var/lib/pacman/local/}%-*-*} )
  342. compadd "$@" -a packages
  343. }
  344. _pacman_all_packages() {
  345. _alternative : \
  346. 'localpkgs:local packages:_pacman_completions_installed_packages' \
  347. 'repopkgs:repository packages:_pacman_completions_all_packages'
  348. }
  349. # provides completions for repository names
  350. _pacman_completions_repositories() {
  351. local -a cmd repositories
  352. repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
  353. # Uniq the array
  354. typeset -U repositories
  355. compadd "$@" -a repositories
  356. }
  357. # builds command for invoking pacman in a _call_program command - extracts
  358. # relevant options already specified (config file, etc)
  359. # $cmd must be declared by calling function
  360. _pacman_get_command() {
  361. # this is mostly nicked from _perforce
  362. cmd=( "pacman" "2>/dev/null")
  363. integer i
  364. for (( i = 2; i < CURRENT - 1; i++ )); do
  365. if [[ ${words[i]} = "--config" || ${words[i]} = "--root" ]]; then
  366. cmd+=( ${words[i,i+1]} )
  367. fi
  368. done
  369. }
  370. # main dispatcher
  371. _pacman_zsh_comp() {
  372. local -a args cmds;
  373. local tmp
  374. args=( ${${${(M)words:#-*}#-}:#-*} )
  375. for tmp in $words; do
  376. cmds+=("${${_pacman_opts_commands[(r)*$tmp\[*]%%\[*}#*\)}")
  377. done
  378. case $args in #$words[2] in
  379. h*)
  380. if (( ${(c)#args} <= 1 && ${(w)#cmds} <= 1 )); then
  381. _pacman_action_help
  382. else
  383. _message "no more arguments"
  384. fi
  385. ;;
  386. *h*)
  387. _message "no more arguments"
  388. ;;
  389. D*)
  390. _pacman_action_database
  391. ;;
  392. F*)
  393. _pacman_action_files
  394. ;;
  395. Q*g*) # ipkg groups
  396. _arguments -s : \
  397. "$_pacman_opts_common[@]" \
  398. "$_pacman_opts_query_modifiers[@]" \
  399. '*:groups:_pacman_completions_installed_groups'
  400. ;;
  401. Q*o*) # file
  402. _arguments -s : \
  403. "$_pacman_opts_common[@]" \
  404. "$_pacman_opts_query_modifiers[@]" \
  405. '*:package file:_files'
  406. ;;
  407. Q*p*) # file *.pkg.tar*
  408. _arguments -s : \
  409. "$_pacman_opts_common[@]" \
  410. "$_pacman_opts_query_modifiers[@]" \
  411. '*:package file:_files -g "*.pkg.tar*~*.sig(.,@)"'
  412. ;;
  413. T*)
  414. _pacman_action_deptest
  415. ;;
  416. Q*)
  417. _pacman_action_query
  418. ;;
  419. P*)
  420. _arguments -s : \
  421. "$_pacman_opts_print_modifiers[@]"
  422. ;;
  423. R*)
  424. _pacman_action_remove
  425. ;;
  426. S*c*) # no completion
  427. _arguments -s : \
  428. '(-c --clean)'{\*-c,\*--clean}'[Remove all files from the cache]' \
  429. "$_pacman_opts_common[@]"
  430. ;;
  431. S*l*) # repos
  432. _arguments -s : \
  433. "$_pacman_opts_common[@]" \
  434. "$_pacman_opts_sync_modifiers[@]" \
  435. '*:package repo:_pacman_completions_repositories' \
  436. ;;
  437. S*g*) # pkg groups
  438. _arguments -s : \
  439. "$_pacman_opts_common[@]" \
  440. "$_pacman_opts_sync_modifiers[@]" \
  441. '*:package group:_pacman_completions_all_groups'
  442. ;;
  443. S*s*)
  444. _arguments -s : \
  445. "$_pacman_opts_common[@]" \
  446. "$_pacman_opts_sync_modifiers[@]" \
  447. '*:search text: '
  448. ;;
  449. S*)
  450. _pacman_action_sync
  451. ;;
  452. T*)
  453. _arguments -s : \
  454. '-T' \
  455. "$_pacman_opts_common[@]" \
  456. ":packages:_pacman_all_packages"
  457. ;;
  458. U*)
  459. _pacman_action_upgrade
  460. ;;
  461. V*)
  462. _pacman_action_version
  463. ;;
  464. Y*)
  465. _arguments -s : \
  466. "$_pacman_opts_yay_modifiers[@]"
  467. ;;
  468. *)
  469. case ${(M)words:#--*} in
  470. *--help*)
  471. if (( ${(w)#cmds} == 1 )); then
  472. _pacman_action_help
  473. else
  474. return 0;
  475. fi
  476. ;;
  477. *--sync*)
  478. _pacman_action_sync
  479. ;;
  480. *--query*)
  481. _pacman_action_query
  482. ;;
  483. *--remove*)
  484. _pacman_action_remove
  485. ;;
  486. *--deptest*)
  487. _pacman_action_deptest
  488. ;;
  489. *--database*)
  490. _pacman_action_database
  491. ;;
  492. *--files*)
  493. _pacman_action_files
  494. ;;
  495. *--version*)
  496. _pacman_action_version
  497. ;;
  498. *--upgrade*)
  499. _pacman_action_upgrade
  500. ;;
  501. *)
  502. _pacman_action_none
  503. ;;
  504. esac
  505. ;;
  506. esac
  507. }
  508. _pacman_comp() {
  509. case "$service" in
  510. yay)
  511. _pacman_zsh_comp "$@"
  512. ;;
  513. *)
  514. _message "Error"
  515. ;;
  516. esac
  517. }
  518. _pacman_comp "$@"