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