Préparation à elvish 0.17 (3)

This commit is contained in:
Benjamin VAUDOUR 2021-10-13 20:49:48 +02:00
parent ad5bd35cca
commit 1a82caec13
18 changed files with 93 additions and 93 deletions

View File

@ -1,6 +1,6 @@
var dir = ~/.config/elvish/aliases var dir = ~/.config/elvish/aliases
for file [(_ = ?(put $dir/*.elv))] { for file [(set _ = ?(put $dir/*.elv))] {
content = (cat $file | slurp) var content = (cat $file | slurp)
eval $content eval $content
} }

View File

@ -1,8 +1,8 @@
#use github.com/zzamboni/elvish-completions/builtins #use github.com/zzamboni/elvish-completions/builtins
use github.com/zzamboni/elvish-completions/cd use github.com/zzamboni/elvish-completions/cd
use github.com/zzamboni/elvish-completions/git use github.com/zzamboni/elvish-completions/git
git:git-command = hub set git:git-command = hub
git:git-completions[checkout] = [ { git:MODIFIED; git:BRANCHES &all } ... ] set git:git-completions[checkout] = [ { git:MODIFIED; git:BRANCHES &all } ... ]
git:init git:init
#use github.com/zzamboni/elvish-completions/ssh #use github.com/zzamboni/elvish-completions/ssh

View File

@ -44,5 +44,5 @@ fn complete [@argv]{
} }
} }
edit:completion:arg-completer[arc] = $complete~ set edit:completion:arg-completer[arc] = $complete~

View File

@ -1,4 +1,4 @@
options = [ var options = [
z z
l l
x x
@ -7,7 +7,7 @@ options = [
h h
] ]
description = [ var description = [
&z='zst compression (default)' &z='zst compression (default)'
&l='lz4 compression' &l='lz4 compression'
&x='xz compression' &x='xz compression'
@ -26,5 +26,5 @@ fn complete [@argv]{
edit:complete-getopt $argv [(-options)] [ $edit:complete-filename~ ...] edit:complete-getopt $argv [(-options)] [ $edit:complete-filename~ ...]
} }
edit:completion:arg-completer[archiver] = $complete~ set edit:completion:arg-completer[archiver] = $complete~

View File

@ -9,4 +9,4 @@ fn complete [@argv]{
file:match-extensions &type=$type $m $@extensions file:match-extensions &type=$type $m $@extensions
} }
edit:completion:arg-completer[desarchiver] = $complete~ set edit:completion:arg-completer[desarchiver] = $complete~

View File

@ -38,4 +38,4 @@ fn complete [@argv]{
} }
} }
edit:completion:arg-completer[kcp] = $complete~ set edit:completion:arg-completer[kcp] = $complete~

View File

@ -56,4 +56,4 @@ fn complete [@argv]{
} }
} }
edit:completion:arg-completer[mpv] = $complete~ set edit:completion:arg-completer[mpv] = $complete~

View File

@ -15,7 +15,7 @@ fn -repo-packages {
peach [p]{ peach [p]{
str:split '/' $p str:split '/' $p
} $packages | peach [e]{ } $packages | peach [e]{
spackages[$e] = $nil set spackages[$e] = $nil
} }
keys $spackages keys $spackages
all $packages all $packages
@ -102,4 +102,4 @@ fn complete [@argv]{
} }
} }
edit:completion:arg-completer[pacman] = $complete~ set edit:completion:arg-completer[pacman] = $complete~

View File

@ -65,17 +65,17 @@ fn -complete-args [hosts cmd @argv]{
} }
var n h = $arg[..$i] $arg[(+ $i 1)..] var n h = $arg[..$i] $arg[(+ $i 1)..]
if (eq $cmd scp) { if (eq $cmd scp) {
i = (str:index $h :) set i = (str:index $h :)
if (>= $i 0) { if (>= $i 0) {
var d = $h[(+ $i 1)..] var d = $h[(+ $i 1)..]
h = $h[..$i] set h = $h[..$i]
if (list:includes $h $hosts) { if (list:includes $h $hosts) {
var p = (-port $cmd @argv) var p = (-port $cmd @argv)
var e = [ (str:split / $d) ] var e = [ (str:split / $d) ]
if (not-eq $e[-1] '') { if (not-eq $e[-1] '') {
d = (str:join / $e[..-1]) set d = (str:join / $e[..-1])
if (eq $d '') { if (eq $d '') {
d = / set d = /
} }
} }
-complete-remote-dir $p $n@$h $d -complete-remote-dir $p $n@$h $d
@ -102,5 +102,5 @@ fn complete [@argv]{
} }
} }
edit:completion:arg-completer[scp] = $complete~ set edit:completion:arg-completer[scp] = $complete~
edit:completion:arg-completer[ssh] = $complete~ set edit:completion:arg-completer[ssh] = $complete~

View File

@ -6,5 +6,5 @@ fn complete [@argv]{
} }
} }
edit:completion:arg-completer[sudo] = $edit:complete-sudo~ set edit:completion:arg-completer[sudo] = $edit:complete-sudo~
#edit:completion:arg-completer[sudo] = $-complete~ #edit:completion:arg-completer[sudo] = $-complete~

View File

@ -12,7 +12,7 @@ var builtin_modules = [
unix unix
] ]
edit:completion:arg-completer[use] = [@argv]{ set edit:completion:arg-completer[use] = [@argv]{
use str use str
use path use path
all $builtin_modules all $builtin_modules

View File

@ -21,7 +21,7 @@ edit:add-var abs~ [n]{
edit:add-var sum~ [@numbers]{ edit:add-var sum~ [@numbers]{
var s = 0 var s = 0
each [e]{ s = (+ $s e) } (to-list $numbers) each [e]{ set s = (+ $s e) } (to-list $numbers)
} }
fn -minmax [t @numbers]{ fn -minmax [t @numbers]{
@ -32,7 +32,7 @@ fn -minmax [t @numbers]{
var m = $l[0] var m = $l[0]
each [n]{ each [n]{
if ($t $n $m) { if ($t $n $m) {
m = $n set m = $n
} }
} $l[1..] } $l[1..]
put $m put $m

View File

@ -2,7 +2,7 @@ use str
use ./list use ./list
use ./map use ./map
search-type = [ var search-type = [
&exact= [m]{ ls $m 2>/dev/null } &exact= [m]{ ls $m 2>/dev/null }
&match= [m]{ put *$m* } &match= [m]{ put *$m* }
&prefix= [m]{ put $m* } &prefix= [m]{ put $m* }
@ -16,7 +16,7 @@ fn -less [f1 f2]{
var fl1 fl2 = (str:to-lower $f1) (str:to-lower $f2) var fl1 fl2 = (str:to-lower $f1) (str:to-lower $f2)
var c = (str:compare $fl1 $fl2) var c = (str:compare $fl1 $fl2)
if (== $c 0) { if (== $c 0) {
c = (str:compare $f1 $f2) set c = (str:compare $f1 $f2)
} }
put (< $c 0) put (< $c 0)
} }
@ -32,12 +32,12 @@ fn -get-results [sort result]{
fn -search [&sort=$false &type=exact @motive]{ fn -search [&sort=$false &type=exact @motive]{
var f result = $search-type[$type] [&] var f result = $search-type[$type] [&]
if (list:empty $motive) { if (list:empty $motive) {
result = (put * | map:to-set) set result = (put * | map:to-set)
} else { } else {
peach [m]{ peach [m]{
try { try {
$f $m | peach [e]{ $f $m | peach [e]{
result[$e] = $nil set result[$e] = $nil
} }
} except e { } } except e { }
} $motive } $motive
@ -48,10 +48,10 @@ fn -search [&sort=$false &type=exact @motive]{
fn match-files [&sort=$false &type=prefix @motive]{ -search &sort=$sort &type=$type $@motive } fn match-files [&sort=$false &type=prefix @motive]{ -search &sort=$sort &type=$type $@motive }
fn match-extensions [&sort=$false &type=deep-prefix motive @extensions]{ fn match-extensions [&sort=$false &type=deep-prefix motive @extensions]{
result = [&] var result = [&]
-search &type=$type $motive | peach [f]{ -search &type=$type $motive | peach [f]{
if (list:contains [e]{ str:has-suffix $f .$e } $extensions) { if (list:contains [e]{ str:has-suffix $f .$e } $extensions) {
result[$f] = $nil set result[$f] = $nil
} }
} }
-get-results $sort $result -get-results $sort $result

View File

@ -33,14 +33,14 @@ fn is-ip [arg]{ or (is-ipv4 $arg) (is-ipv6 $arg) }
fn -long-part6 [p]{ fn -long-part6 [p]{
use str use str
p = (str:to-lower $p) set p = (str:to-lower $p)
c = (- 4 (count $p)) var c = (- 4 (count $p))
put (repeat $c '0' | str:join '')$p put (repeat $c '0' | str:join '')$p
} }
fn -middle-part6 [p]{ fn -middle-part6 [p]{
while (and (> (count $p) 1) (eq $p[0] 0)) { while (and (> (count $p) 1) (eq $p[0] 0)) {
p = $p[1..] set p = $p[1..]
} }
put $p put $p
} }
@ -51,16 +51,16 @@ fn -find-max0 [parts]{
var ci cs f = -1 0 $false var ci cs f = -1 0 $false
list:loop [i p]{ list:loop [i p]{
if (eq $p 0) { if (eq $p 0) {
condition:call $f { cs = (+ $cs 1) } { ci cs f = $i 1 $true } condition:call $f { set cs = (+ $cs 1) } { set ci cs f = $i 1 $true }
} elif $f { } elif $f {
f = $false set f = $false
if (> $cs $s) { if (> $cs $s) {
idx s = $ci $cs set idx s = $ci $cs
} }
} }
} $parts } $parts
if (and $f (> $cs $s)) { if (and $f (> $cs $s)) {
idx s = $ci $cs set idx s = $ci $cs
} }
put $idx $s put $idx $s
} }
@ -77,7 +77,7 @@ fn long6 [ip]{
if (> $c 0) { if (> $c 0) {
var i = (str:index $ip '::') var i = (str:index $ip '::')
var z = (repeat $c ':' | str:join '') var z = (repeat $c ':' | str:join '')
ip = (str:join '' [$ip[..$i] $z $ip[{$i}..]]) set ip = (str:join '' [$ip[..$i] $z $ip[{$i}..]])
} }
str:split ':' $ip | each $-long-part6~ | str:join ':' str:split ':' $ip | each $-long-part6~ | str:join ':'
} }
@ -92,12 +92,12 @@ fn short6 [ip]{
if (>= $i 0) { if (>= $i 0) {
var left right = $parts[..$i] $parts[(+ $i $s)..] var left right = $parts[..$i] $parts[(+ $i $s)..]
if (== (count $left) 0) { if (== (count $left) 0) {
left = [''] set left = ['']
} }
if (== (count $right) 0) { if (== (count $right) 0) {
right = [''] set right = ['']
} }
parts = [$@left '' $@right] set parts = [$@left '' $@right]
} }
str:join ':' $parts str:join ':' $parts
} }
@ -110,7 +110,7 @@ fn -cmp [e1 e2]{
var c = 0 var c = 0
list:loop [i p1]{ list:loop [i p1]{
var p2 = $e2[$i] var p2 = $e2[$i]
c = (condition:cset (< $p1 $p2) -1 (condition:cset (> $p1 $p2) 1 0)) set c = (condition:cset (< $p1 $p2) -1 (condition:cset (> $p1 $p2) 1 0))
if (!= $c 0) { if (!= $c 0) {
break break
} }

View File

@ -40,10 +40,10 @@ fn range [&step=1 b @r]{
var e = 0 var e = 0
if (== $c 0) { if (== $c 0) {
if (> $step 0) { if (> $step 0) {
b e = $e $b set b e = $e $b
} }
} else { } else {
e = $r[0] set e = $r[0]
} }
-r $step $b $e -r $step $b $e
} }
@ -58,16 +58,16 @@ fn indexes [&from=$false &step=1 @argv]{
range &step=$step (- $c 1) range &step=$step (- $c 1)
} else { } else {
if (< $from 0) { if (< $from 0) {
from = (+ $c $from) set from = (+ $c $from)
} }
if (> $step 0) { if (> $step 0) {
if (< $from 0) { if (< $from 0) {
from = 0 set from = 0
} }
range &step=$step $from (- $c 1) range &step=$step $from (- $c 1)
} else { } else {
if (>= $from $c) { if (>= $from $c) {
from = (- $c 1) set from = (- $c 1)
} }
range &step=$step $from 0 range &step=$step $from 0
} }
@ -126,22 +126,22 @@ fn first [&from=$false &reverse=$false cb @argv]{
} else { } else {
var c = (count $l) var c = (count $l)
if (< $from 0) { if (< $from 0) {
from = (+ $c $from) set from = (+ $c $from)
} }
if $reverse { if $reverse {
var e = (+ $from 1) var e = (+ $from 1)
if (> $e $c) { if (> $e $c) {
e = $c set e = $c
} elif (< $e 0) { } elif (< $e 0) {
e = 0 set e = 0
} }
reach $f $l[..$e] reach $f $l[..$e]
} else { } else {
var b = $from var b = $from
if (> $b $c) { if (> $b $c) {
b = $c set b = $c
} elif (< $b 0) { } elif (< $b 0) {
b = 0 set b = 0
} }
each $f $l[$b..] each $f $l[$b..]
} }
@ -160,11 +160,11 @@ fn first-index [&from=$false &reverse=$false cb @argv]{
var idx = -1 var idx = -1
var step = 1 var step = 1
if $reverse { if $reverse {
step = -1 set step = -1
} }
loop &from=$from &step=$step [i v]{ loop &from=$from &step=$step [i v]{
if ($cb $v) { if ($cb $v) {
idx = $i set idx = $i
break break
} }
} $@argv } $@argv
@ -182,7 +182,7 @@ fn search-not [cb @argv]{ search [i v]{ not ($cb $i $v) } $@argv }
fn search-first [&from=$false &reverse=$false cb @argv]{ fn search-first [&from=$false &reverse=$false cb @argv]{
var step = 1 var step = 1
if $reverse { if $reverse {
step = -1 set step = -1
} }
loop &from=$from &step=$step [i v]{ loop &from=$from &step=$step [i v]{
if ($cb $i $v) { if ($cb $i $v) {
@ -204,11 +204,11 @@ fn search-first-index [&from=$false &reverse=$false cb @argv]{
var idx = -1 var idx = -1
var step = 1 var step = 1
if $reverse { if $reverse {
step = -1 set step = -1
} }
loop &from=$from &step=$step [i v]{ loop &from=$from &step=$step [i v]{
if ($cb $i $v) { if ($cb $i $v) {
idx = $i set idx = $i
break break
} }
} $@argv } $@argv
@ -219,7 +219,7 @@ fn contains [cb @argv]{
var e = $false var e = $false
each [v]{ each [v]{
if ($cb $v) { if ($cb $v) {
e = $true set e = $true
break break
} }
} (-p $@argv) } (-p $@argv)
@ -231,7 +231,7 @@ fn exists [cb @argv]{
var e = $false var e = $false
loop [i v]{ loop [i v]{
if ($cb $i $v) { if ($cb $i $v) {
e = $true set e = $true
break break
} }
} $@argv } $@argv
@ -243,7 +243,7 @@ fn includes [v @argv]{ contains [e]{ is $v $e } $@argv }
fn includes-not [v @argv]{ contains-not [e]{ is $v $e } $@argv } fn includes-not [v @argv]{ contains-not [e]{ is $v $e } $@argv }
fn reduce [v cb @argv]{ fn reduce [v cb @argv]{
each [e]{ v = ($cb $v $e) } (to-list $@argv) each [e]{ set v = ($cb $v $e) } (to-list $@argv)
put $v put $v
} }
@ -251,7 +251,7 @@ fn remove-duplicate [@argv]{
var done = [&] var done = [&]
each [v]{ each [v]{
put [&v=$v &e=(has-key $done $v)] put [&v=$v &e=(has-key $done $v)]
done[$v] = $nil set done[$v] = $nil
} (-p $@argv) | each [v]{ } (-p $@argv) | each [v]{
assoc $v k (not $v[e]) assoc $v k (not $v[e])
} | each [v]{ } | each [v]{
@ -263,7 +263,7 @@ fn remove-duplicate [@argv]{
fn premove-duplicate [@argv]{ fn premove-duplicate [@argv]{
var done = [&] var done = [&]
peach [v]{ peach [v]{
done[$v] = $nil set done[$v] = $nil
} (-p $@argv) } (-p $@argv)
keys $done keys $done
} }
@ -271,7 +271,7 @@ fn premove-duplicate [@argv]{
fn swap [i j @argv]{ fn swap [i j @argv]{
var l = (-p $@argv) var l = (-p $@argv)
var c = (count $l) var c = (count $l)
i j = (-i $i $c) (-i $j $c) set i j = (-i $i $c) (-i $j $c)
if (or (== $i $c) (== $j $c)) { if (or (== $i $c) (== $j $c)) {
fail 'Index out of range' fail 'Index out of range'
} }
@ -279,7 +279,7 @@ fn swap [i j @argv]{
all $l all $l
} else { } else {
if (> $i $j) { if (> $i $j) {
i j = $j $i set i j = $j $i
} }
take $i $l take $i $l
put $l[j] put $l[j]

View File

@ -14,8 +14,8 @@ fn value-of [container k &default=$nil]{
fn unzip [container]{ fn unzip [container]{
var lkeys lvalues = [] [] var lkeys lvalues = [] []
keys $container | each [k]{ keys $container | each [k]{
lkeys = [(all $lkeys) $k] set lkeys = [(all $lkeys) $k]
lvalues = [(all $lvalues) $container[$k]] set lvalues = [(all $lvalues) $container[$k]]
} }
put $lkeys $lvalues put $lkeys $lvalues
} }
@ -24,7 +24,7 @@ fn zip [lkeys lvalues]{
var ck cv = (count $lkeys) (count $lvalues) var ck cv = (count $lkeys) (count $lvalues)
var c = $ck var c = $ck
if (> $ck $cv) { if (> $ck $cv) {
c = $cv set c = $cv
} }
var result = [&] var result = [&]
range $c | peach [i]{ range $c | peach [i]{
@ -32,7 +32,7 @@ fn zip [lkeys lvalues]{
} | peach [e]{ } | peach [e]{
assoc $e v $lvalues[$e[i]] assoc $e v $lvalues[$e[i]]
} | each [e]{ } | each [e]{
result[$e[k]] = $e[v] set result[$e[k]] = $e[v]
} }
put $result put $result
} }
@ -46,13 +46,13 @@ fn to-map [@argv]{
fn to-set [@argv]{ fn to-set [@argv]{
use ./list use ./list
var m = [&] var m = [&]
each [k]{ m[$k] = $nil } (list:to-list $@argv) each [k]{ set m[$k] = $nil } (list:to-list $@argv)
put $m put $m
} }
fn mdissoc [container @argv]{ fn mdissoc [container @argv]{
each [k]{ each [k]{
container = (dissoc $container $k) set container = (dissoc $container $k)
} $argv } $argv
put $container put $container
} }
@ -61,7 +61,7 @@ fn massoc [&replace=$true container @argv]{
each [e]{ each [e]{
var k v = $@e var k v = $@e
if (or $replace (not (has-key $container $k))) { if (or $replace (not (has-key $container $k))) {
container[$k] = $v set container[$k] = $v
} }
} $argv } $argv
put $container put $container
@ -71,16 +71,16 @@ fn add [container key @values]{
use ./list use ./list
var values = (list:to-list $values) var values = (list:to-list $values)
if (has-key $container $key) { if (has-key $container $key) {
container[$key] = [(all $container[$key]) $@values] set container[$key] = [(all $container[$key]) $@values]
} else { } else {
container[$key] = $values set container[$key] = $values
} }
put $container put $container
} }
fn join [container container2]{ fn join [container container2]{
keys $container2 | each [k]{ keys $container2 | each [k]{
container[$k] = $container2[$k] set container[$k] = $container2[$k]
} }
put $container put $container
} }

View File

@ -42,7 +42,7 @@ fn join [@opt]{
each [i]{ each [i]{
-joins $opt[{$i0}:$i] -joins $opt[{$i0}:$i]
put $opt[$i] put $opt[$i]
i0 = (+ $i 1) set i0 = (+ $i 1)
} $idx } $idx
-joins $opt[{$i0}:] -joins $opt[{$i0}:]
} }
@ -51,7 +51,7 @@ fn expand [@argv]{ each $split~ (list:-p $@argv) }
fn map [@argv]{ fn map [@argv]{
use ./map use ./map
argv = [(expand $@argv)] set argv = [(expand $@argv)]
var result i c = [&] 0 (count $argv) var result i c = [&] 0 (count $argv)
while (< $i $c) { while (< $i $c) {
var o = $argv[$i] var o = $argv[$i]
@ -60,15 +60,15 @@ fn map [@argv]{
if (< $i (- $c 1)) { if (< $i (- $c 1)) {
var e = $argv[(+ $i 1)] var e = $argv[(+ $i 1)]
if (not (is-option $e)) { if (not (is-option $e)) {
v = [$@v $e] set v = [$@v $e]
i = (+ $i 1) set i = (+ $i 1)
} }
} }
result = (map:add $result $k $@v) set result = (map:add $result $k $@v)
} else { } else {
result = (map:add $result '' [$o]) set result = (map:add $result '' [$o])
} }
i = (+ $i 1) set i = (+ $i 1)
} }
put $result put $result
} }

View File

@ -49,36 +49,36 @@ fn -c2map [col]{
var k = (kind-of $c) var k = (kind-of $c)
var cf = [&min=0] var cf = [&min=0]
if (is $k string) { if (is $k string) {
cf[min] = $c set cf[min] = $c
} elif (is $k map) { } elif (is $k map) {
if (has-key $c min) { if (has-key $c min) {
cf[min] = $c[min] set cf[min] = $c[min]
} }
if (has-key $c align) { if (has-key $c align) {
cf[align] = $c[align] set cf[align] = $c[align]
} }
} }
col[$i] = $cf set col[$i] = $cf
} $col } $col
put $col put $col
} }
fn -parsecols [col &split=$false lst]{ fn -parsecols [col &split=$false lst]{
col = (-c2map $col) set col = (-c2map $col)
var cc lines = (count $col) $lst var cc lines = (count $col) $lst
if $split { if $split {
lines = [ (eawk [_ @args]{ put $args } $lst) ] set lines = [ (eawk [_ @args]{ put $args } $lst) ]
} }
each [l]{ each [l]{
var cl = (count $l) var cl = (count $l)
if (> $cl $cc) { if (> $cl $cc) {
col = [ $@col (range (- $cl $cc) | each [_]{ put [&align=left &min=0] }) ] set col = [ $@col (range (- $cl $cc) | each [_]{ put [&align=left &min=0] }) ]
cc = $cl set cc = $cl
} }
list:loop [i c]{ list:loop [i c]{
var ccl = (+ (count $c) 1) var ccl = (+ (count $c) 1)
if (> $ccl $col[$i][min]) { if (> $ccl $col[$i][min]) {
col[$i][min] = $ccl set col[$i][min] = $ccl
} }
} $l } $l
} $lines } $lines
@ -90,9 +90,9 @@ fn -format [f e]{
if (has-key $f align) { if (has-key $f align) {
var a = $f[align] var a = $f[align]
if (is $a right) { if (is $a right) {
cb = $right~ set cb = $right~
} elif (is $a center) { } elif (is $a center) {
cb = $center~ set cb = $center~
} }
} }
$cb $f[min] $e $cb $f[min] $e
@ -107,8 +107,8 @@ fn -formatline [col line]{
fn format [&col=[] &split=$false @lst]{ fn format [&col=[] &split=$false @lst]{
var lines = (list:-p $@lst) var lines = (list:-p $@lst)
if $split { if $split {
lines = [ (eawk [l @args]{ put $args } $lines) ] set lines = [ (eawk [l @args]{ put $args } $lines) ]
} }
col = (-parsecols $col $lines) set col = (-parsecols $col $lines)
each [l]{ -formatline $col $l } $lines each [l]{ -formatline $col $l } $lines
} }