elvish_config/lib/moi/completion/arc.elv

49 lines
904 B
Plaintext
Raw Normal View History

2020-03-13 14:03:36 +00:00
use moi/util/condition
use moi/util/file
2021-08-27 20:06:49 +00:00
var commands = [
2020-03-13 14:03:36 +00:00
help
archive
unarchive
extract
ls
]
2021-08-27 20:06:49 +00:00
var extensions = [ tar bz2 zip gz lz4 sz xz zst rar ]
2020-03-13 14:03:36 +00:00
2020-07-22 09:24:43 +00:00
fn -comp-commands { all $commands }
2020-03-13 14:03:36 +00:00
2021-12-11 21:09:02 +00:00
fn -comp-archive-files {|m|
2021-08-27 20:06:49 +00:00
var type = (condition:cset (eq $m '') prefix deep-prefix)
2020-03-13 14:03:36 +00:00
file:match-extensions &type=$type $m $@extensions
}
2021-12-11 21:09:02 +00:00
fn -comp-inline-files {|archive|
2020-03-13 14:03:36 +00:00
try {
2021-12-11 21:09:02 +00:00
arc ls $archive | eawk {|_ @argv| put $argv[-1] }
2020-03-13 14:03:36 +00:00
} except e {
nop
}
}
2021-12-11 21:09:02 +00:00
fn complete {|@argv|
2021-08-27 20:06:49 +00:00
var c cmd = (count $argv) $argv[1]
2020-03-13 14:03:36 +00:00
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) {
2021-08-27 20:06:49 +00:00
var archive = $argv[2]
2020-03-13 14:03:36 +00:00
-comp-inline-files $archive
}
}
}
2021-10-13 18:49:48 +00:00
set edit:completion:arg-completer[arc] = $complete~