elvish_config/lib/moi/completion/pacman.elv

106 lines
1.4 KiB
Plaintext

use moi/util/condition
use moi/util/file
use moi/util/list
fn -local-packages { pacman -Q | eawk [_ p @_]{ put $p } }
fn -repo-packages {
var packages = [(pacman -Ss | list:ploop &step=2 [_ v]{
put $v
} | eawk [_ p @_]{
put $p
})]
var spackages = [&]
use str
peach [p]{
str:split '/' $p
} $packages | peach [e]{
spackages[$e] = $nil
}
keys $spackages
all $packages
}
fn -downloaded-packages [m]{
var type = (condition:cset (eq $m '') prefix deep-prefix)
file:match-extensions &type=$type $m tar.zst tar.xz tar.gz tar.bz2
}
fn -local-file [m]{ edit:complete-filename $m }
var options = [
-h
-V
-Q
-Qs
-Ql
-Qi
-Qm
-Qdt
-Qo
-R
-Rsn
-S
-Ss
-Si
-Sii
-Syu
-Syyu
-U
-D
]
var asdeps = [
-S
-U
-D
]
var lpack = [
-Q
-Qs
-Ql
-Qi
-D
-R
-Rsn
]
var rpack = [
-S
-Ss
-Si
-Sii
]
var dpack = [
-U
]
var fpack = [
-Qo
]
fn complete [@argv]{
var c = (count $argv)
if (< $c 3) {
all $options
} else {
var cmd = $argv[1]
if (and (== $c 3) (has-value $asdeps $cmd)) {
put --asdeps --asexplicit
}
if (has-value $lpack $cmd) {
-local-packages
} elif (has-value $rpack $cmd) {
-repo-packages
} elif (has-value $dpack $cmd) {
-downloaded-packages $argv[-1]
} elif (has-value $fpack $cmd) {
-local-file $argv[-1]
}
}
}
edit:completion:arg-completer[pacman] = $complete~