elvish_config/lib/moi/completion/arc.elv

50 lines
908 B
Plaintext
Raw Normal View History

2020-03-13 14:03:36 +00:00
use moi/util/condition
use moi/util/file
commands = [
help
archive
unarchive
extract
ls
]
extensions = [ tar bz2 zip gz lz4 sz xz zst rar ]
2020-07-22 09:24:43 +00:00
fn -comp-commands { all $commands }
2020-03-13 14:03:36 +00:00
fn -comp-archive-files [m]{
local:type = (condition:cset (eq $m '') prefix deep-prefix)
2020-03-13 14:03:36 +00:00
file:match-extensions &type=$type $m $@extensions
}
fn -comp-inline-files [archive]{
try {
arc ls $archive | eawk [_ @argv]{ put $argv[-1] }
2020-03-13 14:03:36 +00:00
} except e {
nop
}
}
fn complete [@argv]{
local:c = (count $argv)
local:cmd = $argv[1]
if (== $c 2) {
-comp-commands
} elif (== $c 3) {
if (not (has-value [help archive] $cmd)) {
-comp-archive-files $argv[-1]
}
} else {
if (eq $cmd archive) {
edit:complete-filename $@argv
} elif (eq $cmd extract) {
local:archive = $argv[2]
-comp-inline-files $archive
}
}
}
edit:completion:arg-completer[arc] = $complete~