elvish_config/lib/moi/completion/arc.elv

49 lines
904 B
Plaintext

use moi/util/condition
use moi/util/file
var commands = [
help
archive
unarchive
extract
ls
]
var extensions = [ tar bz2 zip gz lz4 sz xz zst rar ]
fn -comp-commands { all $commands }
fn -comp-archive-files [m]{
var type = (condition:cset (eq $m '') prefix deep-prefix)
file:match-extensions &type=$type $m $@extensions
}
fn -comp-inline-files [archive]{
try {
arc ls $archive | eawk [_ @argv]{ put $argv[-1] }
} except e {
nop
}
}
fn complete [@argv]{
var c cmd = (count $argv) $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) {
var archive = $argv[2]
-comp-inline-files $archive
}
}
}
set edit:completion:arg-completer[arc] = $complete~