Compatibilité elvish 0.17

This commit is contained in:
Benjamin VAUDOUR 2021-12-11 21:09:02 +00:00
parent be84588373
commit 87eb82a791
43 changed files with 323 additions and 322 deletions

View file

@ -13,20 +13,20 @@ var extensions = [ tar bz2 zip gz lz4 sz xz zst rar ]
fn -comp-commands { all $commands }
fn -comp-archive-files [m]{
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]{
fn -comp-inline-files {|archive|
try {
arc ls $archive | eawk [_ @argv]{ put $argv[-1] }
arc ls $archive | eawk {|_ @argv| put $argv[-1] }
} except e {
nop
}
}
fn complete [@argv]{
fn complete {|@argv|
var c cmd = (count $argv) $argv[1]
if (== $c 2) {
-comp-commands

View file

@ -17,12 +17,12 @@ var description = [
]
fn -options {
each [o]{
each {|o|
put [&short=$o &desc=$description[$o]]
} $options
}
fn complete [@argv]{
fn complete {|@argv|
edit:complete-getopt $argv [(-options)] [ $edit:complete-filename~ ...]
}

View file

@ -3,7 +3,7 @@ use moi/util/file
var extensions = [ tar bz2 zip gz lz4 sz xz zst rar ]
fn complete [@argv]{
fn complete {|@argv|
var m = $argv[-1]
var type = (condition:cset (eq $m '') prefix deep-prefix)
file:match-extensions &type=$type $m $@extensions

View file

@ -29,7 +29,7 @@ var np = [
-V
]
fn complete [@argv]{
fn complete {|@argv|
var c = (count $argv)
if (== $c 2) {
all $options

View file

@ -35,12 +35,12 @@ var extensions = [
wmx
]
fn -files [m]{
fn -files {|m|
var type = (condition:cset (eq $m '') prefix deep-prefix)
file:match-extensions &type=$type $m $@extensions
}
fn complete [@argv]{
fn complete {|@argv|
var c = (count $argv)
if (== $c 2) {
put --speed

View file

@ -2,31 +2,31 @@ use moi/util/condition
use moi/util/file
use moi/util/list
fn -local-packages { pacman -Q | eawk [_ p @_]{ put $p } }
fn -local-packages { pacman -Q | eawk {|_ p @_| put $p } }
fn -repo-packages {
var packages = [(pacman -Ss | list:ploop &step=2 [_ v]{
var packages = [(pacman -Ss | list:ploop &step=2 {|_ v|
put $v
} | eawk [_ p @_]{
} | eawk {|_ p @_|
put $p
})]
var spackages = [&]
use str
peach [p]{
peach {|p|
str:split '/' $p
} $packages | peach [e]{
} $packages | peach {|e|
set spackages[$e] = $nil
}
keys $spackages
all $packages
}
fn -downloaded-packages [m]{
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 }
fn -local-file {|m| edit:complete-filename $m }
var options = [
-h
@ -81,7 +81,7 @@ var fpack = [
-Qo
]
fn complete [@argv]{
fn complete {|@argv|
var c = (count $argv)
if (< $c 3) {
all $options

View file

@ -16,15 +16,15 @@ var names = [
]
fn -kh {
cat ~/.ssh/known_hosts | peach [l]{
cat ~/.ssh/known_hosts | peach {|l|
put [(str:split ' ' $l)]
} | peach [e]{
} | peach {|e|
var domains @_ = $@e
str:split ',' $domains
}
}
fn -port [cmd @argv]{
fn -port {|cmd @argv|
var o = (condition:cset (eq $cmd 'ssh') '-p' '-P')
var margs = (option:map $argv)
var p = (map:value-of $margs $o &default=[])
@ -35,24 +35,24 @@ fn -port [cmd @argv]{
}
}
fn -complete-names []{ each [n]{ put $n'@' } $names }
fn -complete-names {|| each {|n| put $n'@' } $names }
fn -complete-domains [name hosts]{
each [h]{
fn -complete-domains {|name hosts|
each {|h|
put $name@$h
} $hosts
}
fn -complete-remote-dir [port address dir]{
fn -complete-remote-dir {|port address dir|
try {
ssh -p $port $address 'ls '$dir | each [f]{
ssh -p $port $address 'ls '$dir | each {|f|
put $address':'$dir$f
}
} except e {
}
}
fn -complete-args [hosts cmd @argv]{
fn -complete-args {|hosts cmd @argv|
var arg = $argv[-1]
var i = (str:index $arg @)
if (< $i 0) {
@ -87,7 +87,7 @@ fn -complete-args [hosts cmd @argv]{
-complete-domains $n $hosts
}
fn complete [@argv]{
fn complete {|@argv|
var @hosts = (-kh)
var cmd = $argv[0]
var is-ssh = (eq $cmd ssh)

View file

@ -1,4 +1,4 @@
fn complete [@argv]{
fn complete {|@argv|
if (and (> (count $argv) 2) (has-key $edit:completion:arg-completer $argv[1])) {
$edit:completion:arg-completer[$argv[1]] (all $argv[1:])
} else {

View file

@ -12,13 +12,13 @@ var builtin_modules = [
unix
]
set edit:completion:arg-completer[use] = [@argv]{
set edit:completion:arg-completer[use] = {|@argv|
use str
use path
all $builtin_modules
put $libdir/**.elv | each [f]{
put $libdir/**.elv | each {|f|
if (path:is-regular $f) {
str:trim-prefix $f $libdir/
}
} | each [f]{ str:trim-suffix $f .elv }
} | each {|f| str:trim-suffix $f .elv }
}