Passage local: → var (2)
This commit is contained in:
parent
81ab7d87ed
commit
a49f17bc35
|
@ -1,4 +1,4 @@
|
||||||
local:dir = ~/.config/elvish/aliases
|
var dir = ~/.config/elvish/aliases
|
||||||
|
|
||||||
for file [(_ = ?(put $dir/*.elv))] {
|
for file [(_ = ?(put $dir/*.elv))] {
|
||||||
content = (cat $file | slurp)
|
content = (cat $file | slurp)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use moi/util/condition
|
use moi/util/condition
|
||||||
use moi/util/file
|
use moi/util/file
|
||||||
|
|
||||||
commands = [
|
var commands = [
|
||||||
help
|
help
|
||||||
archive
|
archive
|
||||||
unarchive
|
unarchive
|
||||||
|
@ -9,12 +9,12 @@ commands = [
|
||||||
ls
|
ls
|
||||||
]
|
]
|
||||||
|
|
||||||
extensions = [ tar bz2 zip gz lz4 sz xz zst rar ]
|
var extensions = [ tar bz2 zip gz lz4 sz xz zst rar ]
|
||||||
|
|
||||||
fn -comp-commands { all $commands }
|
fn -comp-commands { all $commands }
|
||||||
|
|
||||||
fn -comp-archive-files [m]{
|
fn -comp-archive-files [m]{
|
||||||
local:type = (condition:cset (eq $m '') prefix deep-prefix)
|
var type = (condition:cset (eq $m '') prefix deep-prefix)
|
||||||
file:match-extensions &type=$type $m $@extensions
|
file:match-extensions &type=$type $m $@extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,8 +27,7 @@ fn -comp-inline-files [archive]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete [@argv]{
|
fn complete [@argv]{
|
||||||
local:c = (count $argv)
|
var c cmd = (count $argv) $argv[1]
|
||||||
local:cmd = $argv[1]
|
|
||||||
if (== $c 2) {
|
if (== $c 2) {
|
||||||
-comp-commands
|
-comp-commands
|
||||||
} elif (== $c 3) {
|
} elif (== $c 3) {
|
||||||
|
@ -39,7 +38,7 @@ fn complete [@argv]{
|
||||||
if (eq $cmd archive) {
|
if (eq $cmd archive) {
|
||||||
edit:complete-filename $@argv
|
edit:complete-filename $@argv
|
||||||
} elif (eq $cmd extract) {
|
} elif (eq $cmd extract) {
|
||||||
local:archive = $argv[2]
|
var archive = $argv[2]
|
||||||
-comp-inline-files $archive
|
-comp-inline-files $archive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use moi/util/condition
|
use moi/util/condition
|
||||||
use moi/util/file
|
use moi/util/file
|
||||||
|
|
||||||
extensions = [ tar bz2 zip gz lz4 sz xz zst rar ]
|
var extensions = [ tar bz2 zip gz lz4 sz xz zst rar ]
|
||||||
|
|
||||||
fn complete [@argv]{
|
fn complete [@argv]{
|
||||||
local:m = $argv[-1]
|
var m = $argv[-1]
|
||||||
local:type = (condition:cset (eq $m '') prefix deep-prefix)
|
var type = (condition:cset (eq $m '') prefix deep-prefix)
|
||||||
file:match-extensions &type=$type $m $@extensions
|
file:match-extensions &type=$type $m $@extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
fn -remotes-packages { kcp -lN }
|
fn -remotes-packages { kcp -lN }
|
||||||
|
|
||||||
options = [
|
var options = [
|
||||||
-h
|
-h
|
||||||
-v
|
-v
|
||||||
-i
|
-i
|
||||||
|
@ -21,7 +21,7 @@ options = [
|
||||||
-V
|
-V
|
||||||
]
|
]
|
||||||
|
|
||||||
np = [
|
var np = [
|
||||||
-i
|
-i
|
||||||
-di
|
-di
|
||||||
-s
|
-s
|
||||||
|
@ -30,7 +30,7 @@ np = [
|
||||||
]
|
]
|
||||||
|
|
||||||
fn complete [@argv]{
|
fn complete [@argv]{
|
||||||
local:c = (count $argv)
|
var c = (count $argv)
|
||||||
if (== $c 2) {
|
if (== $c 2) {
|
||||||
all $options
|
all $options
|
||||||
} elif (and (== $c 3) (has-value $np $argv[-2])) {
|
} elif (and (== $c 3) (has-value $np $argv[-2])) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use moi/util/condition
|
use moi/util/condition
|
||||||
use moi/util/file
|
use moi/util/file
|
||||||
|
|
||||||
extensions = [
|
var extensions = [
|
||||||
aac
|
aac
|
||||||
ape
|
ape
|
||||||
avi
|
avi
|
||||||
|
@ -36,12 +36,12 @@ extensions = [
|
||||||
]
|
]
|
||||||
|
|
||||||
fn -files [m]{
|
fn -files [m]{
|
||||||
local:type = (condition:cset (eq $m '') prefix deep-prefix)
|
var type = (condition:cset (eq $m '') prefix deep-prefix)
|
||||||
file:match-extensions &type=$type $m $@extensions
|
file:match-extensions &type=$type $m $@extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete [@argv]{
|
fn complete [@argv]{
|
||||||
c = (count $argv)
|
var c = (count $argv)
|
||||||
if (== $c 2) {
|
if (== $c 2) {
|
||||||
put --speed
|
put --speed
|
||||||
-files $argv[-1]
|
-files $argv[-1]
|
||||||
|
|
|
@ -5,12 +5,12 @@ 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 {
|
fn -repo-packages {
|
||||||
local:packages = [(pacman -Ss | list:ploop &step=2 [_ v]{
|
var packages = [(pacman -Ss | list:ploop &step=2 [_ v]{
|
||||||
put $v
|
put $v
|
||||||
} | eawk [_ p @_]{
|
} | eawk [_ p @_]{
|
||||||
put $p
|
put $p
|
||||||
})]
|
})]
|
||||||
local:spackages = [&]
|
var spackages = [&]
|
||||||
use str
|
use str
|
||||||
peach [p]{
|
peach [p]{
|
||||||
str:split '/' $p
|
str:split '/' $p
|
||||||
|
@ -22,13 +22,13 @@ fn -repo-packages {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn -downloaded-packages [m]{
|
fn -downloaded-packages [m]{
|
||||||
local:type = (condition:cset (eq $m '') prefix deep-prefix)
|
var type = (condition:cset (eq $m '') prefix deep-prefix)
|
||||||
file:match-extensions &type=$type $m tar.zst tar.xz tar.gz tar.bz2
|
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 }
|
||||||
|
|
||||||
options = [
|
var options = [
|
||||||
-h
|
-h
|
||||||
-V
|
-V
|
||||||
-Q
|
-Q
|
||||||
|
@ -50,13 +50,13 @@ options = [
|
||||||
-D
|
-D
|
||||||
]
|
]
|
||||||
|
|
||||||
asdeps = [
|
var asdeps = [
|
||||||
-S
|
-S
|
||||||
-U
|
-U
|
||||||
-D
|
-D
|
||||||
]
|
]
|
||||||
|
|
||||||
lpack = [
|
var lpack = [
|
||||||
-Q
|
-Q
|
||||||
-Qs
|
-Qs
|
||||||
-Ql
|
-Ql
|
||||||
|
@ -66,27 +66,27 @@ lpack = [
|
||||||
-Rsn
|
-Rsn
|
||||||
]
|
]
|
||||||
|
|
||||||
rpack = [
|
var rpack = [
|
||||||
-S
|
-S
|
||||||
-Ss
|
-Ss
|
||||||
-Si
|
-Si
|
||||||
-Sii
|
-Sii
|
||||||
]
|
]
|
||||||
|
|
||||||
dpack = [
|
var dpack = [
|
||||||
-U
|
-U
|
||||||
]
|
]
|
||||||
|
|
||||||
fpack = [
|
var fpack = [
|
||||||
-Qo
|
-Qo
|
||||||
]
|
]
|
||||||
|
|
||||||
fn complete [@argv]{
|
fn complete [@argv]{
|
||||||
local:c = (count $argv)
|
var c = (count $argv)
|
||||||
if (< $c 3) {
|
if (< $c 3) {
|
||||||
all $options
|
all $options
|
||||||
} else {
|
} else {
|
||||||
local:cmd = $argv[1]
|
var cmd = $argv[1]
|
||||||
if (and (== $c 3) (has-value $asdeps $cmd)) {
|
if (and (== $c 3) (has-value $asdeps $cmd)) {
|
||||||
put --asdeps --asexplicit
|
put --asdeps --asexplicit
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,10 @@ use moi/util/list
|
||||||
use moi/util/map
|
use moi/util/map
|
||||||
use moi/util/option
|
use moi/util/option
|
||||||
|
|
||||||
options-ssh = [ 1 2 4 6 A D f g I i L l m o v a b C c e F k N n p q R s T t X x ]
|
var options-ssh = [ 1 2 4 6 A D f g I i L l m o v a b C c e F k N n p q R s T t X x ]
|
||||||
options-scp = [ 3 4 6 B C p q r v c F i l o P S ]
|
var options-scp = [ 3 4 6 B C p q r v c F i l o P S ]
|
||||||
|
|
||||||
names = [
|
var names = [
|
||||||
benjamin
|
benjamin
|
||||||
luence
|
luence
|
||||||
]
|
]
|
||||||
|
@ -19,15 +19,15 @@ fn -kh {
|
||||||
cat ~/.ssh/known_hosts | peach [l]{
|
cat ~/.ssh/known_hosts | peach [l]{
|
||||||
put [(str:split ' ' $l)]
|
put [(str:split ' ' $l)]
|
||||||
} | peach [e]{
|
} | peach [e]{
|
||||||
local:domains @_ = $@e
|
var domains @_ = $@e
|
||||||
str:split ',' $domains
|
str:split ',' $domains
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn -port [cmd @argv]{
|
fn -port [cmd @argv]{
|
||||||
local:o = (condition:cset (eq $cmd 'ssh') '-p' '-P')
|
var o = (condition:cset (eq $cmd 'ssh') '-p' '-P')
|
||||||
local:margs = (option:map $argv)
|
var margs = (option:map $argv)
|
||||||
local:p = (map:value-of $margs $o &default=[])
|
var p = (map:value-of $margs $o &default=[])
|
||||||
if (list:empty $p) {
|
if (list:empty $p) {
|
||||||
put 22
|
put 22
|
||||||
} else {
|
} else {
|
||||||
|
@ -53,8 +53,8 @@ fn -complete-remote-dir [port address dir]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn -complete-args [hosts cmd @argv]{
|
fn -complete-args [hosts cmd @argv]{
|
||||||
local:arg = $argv[-1]
|
var arg = $argv[-1]
|
||||||
local:i = (str:index $arg @)
|
var i = (str:index $arg @)
|
||||||
if (< $i 0) {
|
if (< $i 0) {
|
||||||
-complete-names
|
-complete-names
|
||||||
all $hosts
|
all $hosts
|
||||||
|
@ -63,15 +63,15 @@ fn -complete-args [hosts cmd @argv]{
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
local:n local: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 :)
|
i = (str:index $h :)
|
||||||
if (>= $i 0) {
|
if (>= $i 0) {
|
||||||
local:d = $h[(+ $i 1)..]
|
var d = $h[(+ $i 1)..]
|
||||||
h = $h[..$i]
|
h = $h[..$i]
|
||||||
if (list:includes $h $hosts) {
|
if (list:includes $h $hosts) {
|
||||||
local:p = (-port $cmd @argv)
|
var p = (-port $cmd @argv)
|
||||||
local:e = [ (str:split / $d) ]
|
var e = [ (str:split / $d) ]
|
||||||
if (not-eq $e[-1] '') {
|
if (not-eq $e[-1] '') {
|
||||||
d = (str:join / $e[..-1])
|
d = (str:join / $e[..-1])
|
||||||
if (eq $d '') {
|
if (eq $d '') {
|
||||||
|
@ -88,10 +88,10 @@ fn -complete-args [hosts cmd @argv]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete [@argv]{
|
fn complete [@argv]{
|
||||||
@hosts = (-kh)
|
var @hosts = (-kh)
|
||||||
local:cmd = $argv[0]
|
var cmd = $argv[0]
|
||||||
local:is-ssh = (eq $cmd ssh)
|
var is-ssh = (eq $cmd ssh)
|
||||||
local:po = (condition:cset $is-ssh -p -P)
|
var po = (condition:cset $is-ssh -p -P)
|
||||||
if (<= (count $argv) 2) {
|
if (<= (count $argv) 2) {
|
||||||
all (condition:cset $is-ssh $options-ssh $options-scp)
|
all (condition:cset $is-ssh $options-ssh $options-scp)
|
||||||
-complete-args $hosts $@argv
|
-complete-args $hosts $@argv
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
local:libdir = $E:HOME/.config/elvish/lib
|
var libdir = $E:HOME/.config/elvish/lib
|
||||||
local:builtin_modules = [
|
var builtin_modules = [
|
||||||
builtin
|
builtin
|
||||||
epm
|
epm
|
||||||
file
|
file
|
||||||
|
|
|
@ -20,16 +20,16 @@ edit:add-var abs~ [n]{
|
||||||
}
|
}
|
||||||
|
|
||||||
edit:add-var sum~ [@numbers]{
|
edit:add-var sum~ [@numbers]{
|
||||||
local:s = 0
|
var s = 0
|
||||||
each [e]{ s = (+ $s e) } (to-list $numbers)
|
each [e]{ s = (+ $s e) } (to-list $numbers)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn -minmax [t @numbers]{
|
fn -minmax [t @numbers]{
|
||||||
local:l = (to-list $@numbers)
|
var l = (to-list $@numbers)
|
||||||
if (== (count $l) 0) {
|
if (== (count $l) 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
local:m = $l[0]
|
var m = $l[0]
|
||||||
each [n]{
|
each [n]{
|
||||||
if ($t $n $m) {
|
if ($t $n $m) {
|
||||||
m = $n
|
m = $n
|
||||||
|
|
|
@ -11,7 +11,7 @@ fn mset [c t f]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call [c t f @argv]{
|
fn call [c t f @argv]{
|
||||||
local:v = (cset $c $t $f)
|
var v = (cset $c $t $f)
|
||||||
if (is (kind-of $v) fn) {
|
if (is (kind-of $v) fn) {
|
||||||
$v $@argv
|
$v $@argv
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -13,8 +13,8 @@ search-type = [
|
||||||
]
|
]
|
||||||
|
|
||||||
fn -less [f1 f2]{
|
fn -less [f1 f2]{
|
||||||
local:fl1 local:fl2 = (str:to-lower $f1) (str:to-lower $f2)
|
var fl1 fl2 = (str:to-lower $f1) (str:to-lower $f2)
|
||||||
local:c = (str:compare $fl1 $fl2)
|
var c = (str:compare $fl1 $fl2)
|
||||||
if (== $c 0) {
|
if (== $c 0) {
|
||||||
c = (str:compare $f1 $f2)
|
c = (str:compare $f1 $f2)
|
||||||
}
|
}
|
||||||
|
@ -30,16 +30,15 @@ fn -get-results [sort result]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn -search [&sort=$false &type=exact @motive]{
|
fn -search [&sort=$false &type=exact @motive]{
|
||||||
local:f = $search-type[$type]
|
var f result = $search-type[$type] [&]
|
||||||
local:result = [&]
|
|
||||||
if (list:empty $motive) {
|
if (list:empty $motive) {
|
||||||
result = (put * | map:to-set)
|
result = (put * | map:to-set)
|
||||||
} else {
|
} else {
|
||||||
peach [m]{
|
peach [m]{
|
||||||
local:m = $m
|
var m = $m
|
||||||
try {
|
try {
|
||||||
$f $m | peach [e]{
|
$f $m | peach [e]{
|
||||||
local:e = $e
|
var e = $e
|
||||||
result[$e] = $nil
|
result[$e] = $nil
|
||||||
}
|
}
|
||||||
} except e { }
|
} except e { }
|
||||||
|
@ -53,7 +52,7 @@ fn match-files [&sort=$false &type=prefix @motive]{ -search &sort=$sort &type=$t
|
||||||
fn match-extensions [&sort=$false &type=deep-prefix motive @extensions]{
|
fn match-extensions [&sort=$false &type=deep-prefix motive @extensions]{
|
||||||
result = [&]
|
result = [&]
|
||||||
-search &type=$type $motive | peach [f]{
|
-search &type=$type $motive | peach [f]{
|
||||||
local:f = $f
|
var f = $f
|
||||||
if (list:contains [e]{ str:has-suffix $f .$e } $extensions) {
|
if (list:contains [e]{ str:has-suffix $f .$e } $extensions) {
|
||||||
result[$f] = $nil
|
result[$f] = $nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ fn is-ipv4 [arg]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is-ipv6 [arg]{
|
fn is-ipv6 [arg]{
|
||||||
local:p = '[0-9a-fA-F]{1,4}'
|
var p = '[0-9a-fA-F]{1,4}'
|
||||||
local:g1 local:g2 = '('$p':)' '(:'$p')'
|
var g1 g2 = '('$p':)' '(:'$p')'
|
||||||
local:cases = [
|
var cases = [
|
||||||
$g1'{7,7}'$p
|
$g1'{7,7}'$p
|
||||||
$g1'{1,7}:'
|
$g1'{1,7}:'
|
||||||
$g1'{1,6}:'$p
|
$g1'{1,6}:'$p
|
||||||
|
@ -25,7 +25,7 @@ fn is-ipv6 [arg]{
|
||||||
':'$g2'{1,7}'
|
':'$g2'{1,7}'
|
||||||
'::'
|
'::'
|
||||||
]
|
]
|
||||||
local:r = '^('(str:join '|' $cases)')$'
|
var r = '^('(str:join '|' $cases)')$'
|
||||||
put (re:match $r $arg)
|
put (re:match $r $arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,8 +47,8 @@ fn -middle-part6 [p]{
|
||||||
|
|
||||||
fn -find-max0 [parts]{
|
fn -find-max0 [parts]{
|
||||||
use ./list
|
use ./list
|
||||||
local:idx local:s = -1 1
|
var idx s = -1 1
|
||||||
local:ci local:cs local: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 { cs = (+ $cs 1) } { ci cs f = $i 1 $true }
|
||||||
|
@ -73,11 +73,11 @@ fn long6 [ip]{
|
||||||
repeat 8 '0000' | str:join ':'
|
repeat 8 '0000' | str:join ':'
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
local:c = (- 7 (str:count $ip ':'))
|
var c = (- 7 (str:count $ip ':'))
|
||||||
if (> $c 0) {
|
if (> $c 0) {
|
||||||
local:i = (str:index $ip '::')
|
var i = (str:index $ip '::')
|
||||||
local:z = (repeat $c ':' | str:join '')
|
var z = (repeat $c ':' | str:join '')
|
||||||
ip = (str:join '' [$ip[..$i] $z $ip[{$i}..]])
|
ip = (str:join '' [$ip[..$i] $z $ip[{$i}..]])
|
||||||
}
|
}
|
||||||
str:split ':' $ip | each $-long-part6~ | str:join ':'
|
str:split ':' $ip | each $-long-part6~ | str:join ':'
|
||||||
}
|
}
|
||||||
|
@ -87,10 +87,10 @@ fn middle6 [ip]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn short6 [ip]{
|
fn short6 [ip]{
|
||||||
local:parts = [(str:split ':' (middle6 $ip))]
|
var parts = [(str:split ':' (middle6 $ip))]
|
||||||
local:i local:s = (-find-max0 $parts)
|
var i s = (-find-max0 $parts)
|
||||||
if (>= $i 0) {
|
if (>= $i 0) {
|
||||||
local:left local:right = $parts[..$i] $parts[(+ $i $s)..]
|
var left right = $parts[..$i] $parts[(+ $i $s)..]
|
||||||
if (== (count $left) 0) {
|
if (== (count $left) 0) {
|
||||||
left = ['']
|
left = ['']
|
||||||
}
|
}
|
||||||
|
@ -107,9 +107,9 @@ fn is-ip [arg]{ or (is-ipv4 $arg) (is-ipv6 $arg) }
|
||||||
fn -cmp [e1 e2]{
|
fn -cmp [e1 e2]{
|
||||||
use ./list
|
use ./list
|
||||||
use ./condition
|
use ./condition
|
||||||
local:c = 0
|
var c = 0
|
||||||
list:loop [i p1]{
|
list:loop [i p1]{
|
||||||
local:p2 = $e2[$i]
|
var p2 = $e2[$i]
|
||||||
c = (condition:cset (< $p1 $p2) -1 (condition:cset (> $p1 $p2) 1 0))
|
c = (condition:cset (< $p1 $p2) -1 (condition:cset (> $p1 $p2) 1 0))
|
||||||
if (!= $c 0) {
|
if (!= $c 0) {
|
||||||
break
|
break
|
||||||
|
|
|
@ -12,21 +12,21 @@ fn value-of [container k &default=$nil]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unzip [container]{
|
fn unzip [container]{
|
||||||
local:lkeys local:lvalues = [] []
|
var lkeys lvalues = [] []
|
||||||
keys $container | each [k]{
|
keys $container | each [k]{
|
||||||
lkeys = [(all $lkeys) $k]
|
lkeys = [(all $lkeys) $k]
|
||||||
lvalues = [(all $lvalues) $container[$k]]
|
lvalues = [(all $lvalues) $container[$k]]
|
||||||
}
|
}
|
||||||
put $lkeys $lvalues
|
put $lkeys $lvalues
|
||||||
}
|
}
|
||||||
|
|
||||||
fn zip [lkeys lvalues]{
|
fn zip [lkeys lvalues]{
|
||||||
local:ck local:cv = (count $lkeys) (count $lvalues)
|
var ck cv = (count $lkeys) (count $lvalues)
|
||||||
local:c = $ck
|
var c = $ck
|
||||||
if (> $ck $cv) {
|
if (> $ck $cv) {
|
||||||
c = $cv
|
c = $cv
|
||||||
}
|
}
|
||||||
local:result = [&]
|
var result = [&]
|
||||||
range $c | peach [i]{
|
range $c | peach [i]{
|
||||||
put [&k=$lkeys[$i] &i=$i]
|
put [&k=$lkeys[$i] &i=$i]
|
||||||
} | peach [e]{
|
} | peach [e]{
|
||||||
|
@ -39,13 +39,13 @@ fn zip [lkeys lvalues]{
|
||||||
|
|
||||||
fn to-map [@argv]{
|
fn to-map [@argv]{
|
||||||
use ./list
|
use ./list
|
||||||
local:container = (list:to-list $@argv)
|
var container = (list:to-list $@argv)
|
||||||
zip [(range (count $container))] $container
|
zip [(range (count $container))] $container
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to-set [@argv]{
|
fn to-set [@argv]{
|
||||||
use ./list
|
use ./list
|
||||||
local:m = [&]
|
var m = [&]
|
||||||
each [k]{ m[$k] = $nil } (list:to-list $@argv)
|
each [k]{ m[$k] = $nil } (list:to-list $@argv)
|
||||||
put $m
|
put $m
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ fn mdissoc [container @argv]{
|
||||||
|
|
||||||
fn massoc [&replace=$true container @argv]{
|
fn massoc [&replace=$true container @argv]{
|
||||||
each [e]{
|
each [e]{
|
||||||
local:k local: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
|
container[$k] = $v
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ fn massoc [&replace=$true container @argv]{
|
||||||
|
|
||||||
fn add [container key @values]{
|
fn add [container key @values]{
|
||||||
use ./list
|
use ./list
|
||||||
local: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]
|
container[$key] = [(all $container[$key]) $@values]
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -11,7 +11,7 @@ fn -splitm [o]{ each [e]{ put -$e } $o[1:] }
|
||||||
|
|
||||||
fn -splitl [o]{
|
fn -splitl [o]{
|
||||||
if (str:contains $o '=') {
|
if (str:contains $o '=') {
|
||||||
local:opt @local:value = (str:split '=' $o)
|
var opt @value = (str:split '=' $o)
|
||||||
put $opt
|
put $opt
|
||||||
str:join '=' $value
|
str:join '=' $value
|
||||||
} else {
|
} else {
|
||||||
|
@ -30,15 +30,15 @@ fn split [o]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn -joins [opt]{
|
fn -joins [opt]{
|
||||||
local:o = (each [o]{ put $o[1:] } $opt | str:join '')
|
var o = (each [o]{ put $o[1:] } $opt | str:join '')
|
||||||
if (not-eq $o '') { put -$o }
|
if (not-eq $o '') { put -$o }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn join [@opt]{
|
fn join [@opt]{
|
||||||
local:opt = (list:-p $@opt)
|
var opt = (list:-p $@opt)
|
||||||
local:cb = [o]{ or (is-soption $o) (is-moptions $o) }
|
var cb = [o]{ or (is-soption $o) (is-moptions $o) }
|
||||||
local:idx = [(list:filter-index-not $cb $opt)]
|
var idx = [(list:filter-index-not $cb $opt)]
|
||||||
local:i0 = 0
|
var i0 = 0
|
||||||
each [i]{
|
each [i]{
|
||||||
-joins $opt[{$i0}:$i]
|
-joins $opt[{$i0}:$i]
|
||||||
put $opt[$i]
|
put $opt[$i]
|
||||||
|
@ -52,14 +52,13 @@ fn expand [@argv]{ each $split~ (list:-p $@argv) }
|
||||||
fn map [@argv]{
|
fn map [@argv]{
|
||||||
use ./map
|
use ./map
|
||||||
argv = [(expand $@argv)]
|
argv = [(expand $@argv)]
|
||||||
local:result = [&]
|
var result i c = [&] 0 (count $argv)
|
||||||
local:i local:c = 0 (count $argv)
|
|
||||||
while (< $i $c) {
|
while (< $i $c) {
|
||||||
local:o = $argv[$i]
|
var o = $argv[$i]
|
||||||
if (is-option $o) {
|
if (is-option $o) {
|
||||||
local:k local:v = $o []
|
var k v = $o []
|
||||||
if (< $i (- $c 1)) {
|
if (< $i (- $c 1)) {
|
||||||
local:e = $argv[(+ $i 1)]
|
var e = $argv[(+ $i 1)]
|
||||||
if (not (is-option $e)) {
|
if (not (is-option $e)) {
|
||||||
v = [$@v $e]
|
v = [$@v $e]
|
||||||
i = (+ $i 1)
|
i = (+ $i 1)
|
||||||
|
|
|
@ -6,8 +6,8 @@ fn -repeat [n s]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn left [size s]{
|
fn left [size s]{
|
||||||
local:ss = (count $s)
|
var ss = (count $s)
|
||||||
local:d = (- $size $ss)
|
var d = (- $size $ss)
|
||||||
if (<= $d 0) {
|
if (<= $d 0) {
|
||||||
put $s[:$size]
|
put $s[:$size]
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,8 +16,8 @@ fn left [size s]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn right [size s]{
|
fn right [size s]{
|
||||||
local:ss = (count $s)
|
var ss = (count $s)
|
||||||
local:d = (- $size $ss)
|
var d = (- $size $ss)
|
||||||
if (<= $d 0) {
|
if (<= $d 0) {
|
||||||
put $s[:$size]
|
put $s[:$size]
|
||||||
} else {
|
} else {
|
||||||
|
@ -27,15 +27,15 @@ fn right [size s]{
|
||||||
|
|
||||||
fn center [size s]{
|
fn center [size s]{
|
||||||
use math
|
use math
|
||||||
local:ss = (count $s)
|
var ss = (count $s)
|
||||||
local:d = (- $size $ss)
|
var d = (- $size $ss)
|
||||||
if (<= $d 0) {
|
if (<= $d 0) {
|
||||||
local:l = (math:ceil (/ -$d 2))
|
var l = (math:ceil (/ -$d 2))
|
||||||
local:r = (- (+ $ss $d) $l)
|
var r = (- (+ $ss $d) $l)
|
||||||
put $s[$l':'$r]
|
put $s[$l':'$r]
|
||||||
} else {
|
} else {
|
||||||
local:l = (math:ceil (/ $d 2))
|
var l = (math:ceil (/ $d 2))
|
||||||
local:r = (- $d $l)
|
var r = (- $d $l)
|
||||||
put (-repeat $l ' ')$s(-repeat $r ' ')
|
put (-repeat $l ' ')$s(-repeat $r ' ')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,8 @@ fn -c2map [col]{
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
list:loop [i c]{
|
list:loop [i c]{
|
||||||
local:k = (kind-of $c)
|
var k = (kind-of $c)
|
||||||
local:cf = [&min=0]
|
var cf = [&min=0]
|
||||||
if (is $k string) {
|
if (is $k string) {
|
||||||
cf[min] = $c
|
cf[min] = $c
|
||||||
} elif (is $k map) {
|
} elif (is $k map) {
|
||||||
|
@ -65,19 +65,18 @@ fn -c2map [col]{
|
||||||
|
|
||||||
fn -parsecols [col &split=$false lst]{
|
fn -parsecols [col &split=$false lst]{
|
||||||
col = (-c2map $col)
|
col = (-c2map $col)
|
||||||
local:cc = (count $col)
|
var cc lines = (count $col) $lst
|
||||||
local:lines = $lst
|
|
||||||
if $split {
|
if $split {
|
||||||
lines = [ (eawk [_ @args]{ put $args } $lst) ]
|
lines = [ (eawk [_ @args]{ put $args } $lst) ]
|
||||||
}
|
}
|
||||||
each [l]{
|
each [l]{
|
||||||
local:cl = (count $l)
|
var cl = (count $l)
|
||||||
if (> $cl $cc) {
|
if (> $cl $cc) {
|
||||||
col = [ $@col (range (- $cl $cc) | each [_]{ put [&align=left &min=0] }) ]
|
col = [ $@col (range (- $cl $cc) | each [_]{ put [&align=left &min=0] }) ]
|
||||||
cc = $cl
|
cc = $cl
|
||||||
}
|
}
|
||||||
list:loop [i c]{
|
list:loop [i c]{
|
||||||
local:ccl = (+ (count $c) 1)
|
var ccl = (+ (count $c) 1)
|
||||||
if (> $ccl $col[$i][min]) {
|
if (> $ccl $col[$i][min]) {
|
||||||
col[$i][min] = $ccl
|
col[$i][min] = $ccl
|
||||||
}
|
}
|
||||||
|
@ -87,9 +86,9 @@ fn -parsecols [col &split=$false lst]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn -format [f e]{
|
fn -format [f e]{
|
||||||
local:cb = $left~
|
var cb = $left~
|
||||||
if (has-key $f align) {
|
if (has-key $f align) {
|
||||||
local:a = $f[align]
|
var a = $f[align]
|
||||||
if (is $a right) {
|
if (is $a right) {
|
||||||
cb = $right~
|
cb = $right~
|
||||||
} elif (is $a center) {
|
} elif (is $a center) {
|
||||||
|
@ -106,7 +105,7 @@ fn -formatline [col line]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format [&col=[] &split=$false @lst]{
|
fn format [&col=[] &split=$false @lst]{
|
||||||
local:lines = (list:-p $@lst)
|
var lines = (list:-p $@lst)
|
||||||
if $split {
|
if $split {
|
||||||
lines = [ (eawk [l @args]{ put $args } $lines) ]
|
lines = [ (eawk [l @args]{ put $args } $lines) ]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue