maj de la configuration
This commit is contained in:
parent
df4f2c07c1
commit
2dac13303d
20 changed files with 210 additions and 69 deletions
|
|
@ -11,6 +11,7 @@ alias:new cat bat -pp
|
|||
alias:new midi e:fluidsynth -a pulseaudio /usr/share/soundfonts/FluidR3_GM.sf2
|
||||
alias:new timidity e:timidity -a -K -1
|
||||
alias:new git e:hub
|
||||
alias:new dig e:dig +noall +answer
|
||||
|
||||
#alias:new pacmanhisto cat /var/log/pacman.log | grep "ALPM" | grep
|
||||
alias:new pf e:pkgfile -vri
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ commands = [
|
|||
|
||||
extensions = [ tar bz2 zip gz lz4 sz xz zst rar ]
|
||||
|
||||
fn -comp-commands { explode $commands }
|
||||
fn -comp-commands { all $commands }
|
||||
|
||||
fn -comp-archive-files [m]{
|
||||
local:type = (condition:set (eq $m '') prefix deep-prefix)
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ np = [
|
|||
fn complete [@argv]{
|
||||
local:c = (count $argv)
|
||||
if (== $c 2) {
|
||||
explode $options
|
||||
all $options
|
||||
} elif (and (== $c 3) (has-value $np $argv[-2])) {
|
||||
-remotes-packages
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,13 +11,14 @@ fn -repo-packages {
|
|||
put $p
|
||||
})]
|
||||
local:spackages = [&]
|
||||
use str
|
||||
peach [p]{
|
||||
splits '/' $p
|
||||
str:split '/' $p
|
||||
} $packages | peach [e]{
|
||||
spackages[$e] = $nil
|
||||
}
|
||||
keys $spackages
|
||||
explode $packages
|
||||
all $packages
|
||||
}
|
||||
|
||||
fn -downloaded-packages [m]{
|
||||
|
|
@ -83,7 +84,7 @@ fpack = [
|
|||
fn complete [@argv]{
|
||||
local:c = (count $argv)
|
||||
if (< $c 3) {
|
||||
explode $options
|
||||
all $options
|
||||
} else {
|
||||
local:cmd = $argv[1]
|
||||
if (and (== $c 3) (has-value $asdeps $cmd)) {
|
||||
|
|
|
|||
|
|
@ -44,11 +44,11 @@ fn -init-hosts {
|
|||
fn -init-known-hosts {
|
||||
local:khosts = [&22=[&]]
|
||||
cat ~/.ssh/known_hosts | peach [l]{
|
||||
put [(splits ' ' $l)]
|
||||
put [(str:split ' ' $l)]
|
||||
} | peach [e]{
|
||||
local:domains @local:id = $@e
|
||||
id = (joins ' ' $id)
|
||||
splits ',' $domains | peach [d]{
|
||||
id = (str:join ' ' $id)
|
||||
str:split ',' $domains | peach [d]{
|
||||
local:d = $d
|
||||
local:port = 22
|
||||
if (eq $d[0] '[') {
|
||||
|
|
@ -105,10 +105,10 @@ fn -init-history {
|
|||
if (and (< $i $c) (or (and (eq $cmd ssh) (eq $arg -p)) (eq $arg -P))) {
|
||||
port = $argv[(+ $i 1)]
|
||||
} else {
|
||||
local:nd = [(splits '@' $arg)]
|
||||
local:nd = [(str:split '@' $arg)]
|
||||
if (== (count $nd) 2) {
|
||||
name = $nd[0]
|
||||
domain @_ = (splits ':' $nd[1])
|
||||
domain @_ = (str:split ':' $nd[1])
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -207,14 +207,14 @@ fn -complete-args [cmd @argv]{
|
|||
port = $port[-1]
|
||||
}
|
||||
local:larg = $argv[-1]
|
||||
local:name @local:host = (splits '@' $larg)
|
||||
local:name @local:host = (str:split '@' $larg)
|
||||
if (list:empty $host) {
|
||||
-known-names &port=$port | each [n]{ put $n'@' }
|
||||
if (eq $cmd 'scp') {
|
||||
file:match-files $larg
|
||||
}
|
||||
} else {
|
||||
host @_ = (splits ':' $host[0])
|
||||
host @_ = (str:split ':' $host[0])
|
||||
local:check = [h]{ has-prefix $h $host }
|
||||
local:khosts = [(-known-hosts &port=$port &name=$name)]
|
||||
if (not (list:contains $check $khosts)) {
|
||||
|
|
@ -224,7 +224,7 @@ fn -complete-args [cmd @argv]{
|
|||
}
|
||||
}
|
||||
each [h]{ put $name'@'$h } $khosts
|
||||
explode $khosts
|
||||
all $khosts
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
fn complete [@argv]{
|
||||
if (and (> (count $argv) 2) (has-key $edit:completion:arg-completer $argv[1])) {
|
||||
$edit:completion:arg-completer[$argv[1]] (explode $argv[1:])
|
||||
$edit:completion:arg-completer[$argv[1]] (all $argv[1:])
|
||||
} else {
|
||||
edit:complete-sudo $@argv
|
||||
}
|
||||
|
|
|
|||
BIN
lib/moi/util/.list.elv.kate-swp
Normal file
BIN
lib/moi/util/.list.elv.kate-swp
Normal file
Binary file not shown.
|
|
@ -7,7 +7,7 @@ fn set [c t f]{
|
|||
}
|
||||
|
||||
fn mset [c t f]{
|
||||
explode (set $c $t $f)
|
||||
all (set $c $t $f)
|
||||
}
|
||||
|
||||
fn call [c t f @argv]{
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@ fn -less [f1 f2]{
|
|||
|
||||
fn -get-results [sort result]{
|
||||
if $sort {
|
||||
use ./list
|
||||
keys $result | list:sort $-less~
|
||||
keys $result | order $-less~
|
||||
} else {
|
||||
keys $result
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
use re
|
||||
use str
|
||||
|
||||
fn is-ipv4 [arg]{
|
||||
use re
|
||||
if (not (re:match '^([0-9]{1,3}\.){3}[0-9]{1,3}$' $arg)) {
|
||||
put $false
|
||||
} else {
|
||||
use ./list
|
||||
not (splits '.' $arg | list:contains [p]{ > $p 255 })
|
||||
not (str:split '.' $arg | list:contains [p]{ > $p 255 })
|
||||
}
|
||||
}
|
||||
|
||||
fn is-ipv6 [arg]{
|
||||
use re
|
||||
local:p = '[0-9a-fA-F]{1,4}'
|
||||
local:g1 local:g2 = '('$p':)' '(:'$p')'
|
||||
local:cases = [
|
||||
|
|
@ -24,15 +25,17 @@ fn is-ipv6 [arg]{
|
|||
':'$g2'{1,7}'
|
||||
'::'
|
||||
]
|
||||
local:r = '^('(joins '|' $cases)')$'
|
||||
local:r = '^('(str:join '|' $cases)')$'
|
||||
put (re:match $r $arg)
|
||||
}
|
||||
|
||||
fn is-ip [arg]{ or (is-ipv4 $arg) (is-ipv6 $arg) }
|
||||
|
||||
fn -long-part6 [p]{
|
||||
use str
|
||||
p = (str:to-lower $p)
|
||||
c = (- 4 (count $p))
|
||||
put (repeat $c '0' | joins '')$p
|
||||
put (repeat $c '0' | str:join '')$p
|
||||
}
|
||||
|
||||
fn -middle-part6 [p]{
|
||||
|
|
@ -68,25 +71,24 @@ fn long6 [ip]{
|
|||
fail 'Not an IPv6'
|
||||
}
|
||||
if (eq $ip '::') {
|
||||
repeat 8 '0000' | joins ':'
|
||||
repeat 8 '0000' | str:join ':'
|
||||
return
|
||||
}
|
||||
use str
|
||||
local:c = (- 7 (str:count $ip ':'))
|
||||
if (> $c 0) {
|
||||
local:i = (str:index $ip '::')
|
||||
local:z = (repeat $c ':' | joins '')
|
||||
ip = (joins '' [$ip[:$i] $z $ip[{$i}:]])
|
||||
local:z = (repeat $c ':' | str:join '')
|
||||
ip = (str:join '' [$ip[:$i] $z $ip[{$i}:]])
|
||||
}
|
||||
splits ':' $ip | each $-long-part6~ | joins ':'
|
||||
str:split ':' $ip | each $-long-part6~ | str:join ':'
|
||||
}
|
||||
|
||||
fn middle6 [ip]{
|
||||
splits ':' (long6 $ip) | each $-middle-part6~ | joins ':'
|
||||
str:split ':' (long6 $ip) | each $-middle-part6~ | str:join ':'
|
||||
}
|
||||
|
||||
fn short6 [ip]{
|
||||
local:parts = [(splits ':' (middle6 $ip))]
|
||||
local:parts = [(str:split ':' (middle6 $ip))]
|
||||
local:i local:s = (-find-max0 $parts)
|
||||
if (>= $i 0) {
|
||||
local:left local:right = $parts[:$i] $parts[(+ $i $s):]
|
||||
|
|
@ -98,7 +100,7 @@ fn short6 [ip]{
|
|||
}
|
||||
parts = [$@left '' $@right]
|
||||
}
|
||||
joins ':' $parts
|
||||
str:join ':' $parts
|
||||
}
|
||||
|
||||
fn is-ip [arg]{ or (is-ipv4 $arg) (is-ipv6 $arg) }
|
||||
|
|
@ -119,14 +121,34 @@ fn -cmp [e1 e2]{
|
|||
|
||||
fn cmp4 [ip1 ip2]{
|
||||
if (or (not (is-ipv4 $ip1)) (not (is-ipv4 $ip2))) {
|
||||
fail 'Not an IPv4'
|
||||
fail 'Not an IPv4 '$ip1' → '$ip2
|
||||
}
|
||||
-cmp [(splits . $ip1)] [(splits . $ip2)]
|
||||
-cmp [(str:split . $ip1)] [(str:split . $ip2)]
|
||||
}
|
||||
|
||||
fn cmp6 [ip1 ip2]{
|
||||
if (or (not (is-ipv6 $ip1)) (not (is-ipv6 $ip2))) {
|
||||
fail 'Not an IPv6'
|
||||
fail 'Not an IPv6: '$ip1' → '$ip2
|
||||
}
|
||||
-cmp [(str:split : (middle6 $ip1))] [(str:split : (middle6 $ip2))]
|
||||
}
|
||||
|
||||
fn cmp [ip1 ip2]{
|
||||
if (is-ipv4 $ip1) {
|
||||
if (is-ipv4 $ip2) {
|
||||
cmp4 $ip1 $ip2
|
||||
} else {
|
||||
put -1
|
||||
}
|
||||
} elif (is-ipv6 $ip1) {
|
||||
if (is-ipv4 $ip2) {
|
||||
put 1
|
||||
} elif (is-ipv6 $ip2) {
|
||||
cmp6 $ip1 $ip2
|
||||
} else {
|
||||
put -1
|
||||
}
|
||||
} else {
|
||||
fali 'Not an IP: '$ip1' → '$ip2
|
||||
}
|
||||
-cmp [(splits : (middle6 $ip1))] [(splits : (middle6 $ip2))]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -206,12 +206,12 @@ fn -swap [i j l]{
|
|||
fail 'Index out of range'
|
||||
}
|
||||
if (eq $i $j) {
|
||||
explode $l
|
||||
all $l
|
||||
} else {
|
||||
i j = (condition:mset (< $i $j) [$i $j] [$j $i])
|
||||
take $i $l
|
||||
put $l[j]
|
||||
explode $l[(+ $i 1):$j]
|
||||
all $l[(+ $i 1):$j]
|
||||
put $l[$i]
|
||||
drop (+ $j 1) $l
|
||||
}
|
||||
|
|
@ -270,6 +270,9 @@ fn contains-not [cb @argv]{ contains [v]{ not ($cb $v) } $@argv }
|
|||
fn exists [cb @argv]{ -exists $cb (-p $@argv) }
|
||||
fn exists-not [cb @argv]{ exists [i v]{ $cb $i $v } $@argv }
|
||||
|
||||
fn includes [v @argv]{ contains [e]{ is $v $e } $@argv }
|
||||
fn includes-not [v @argv]{ contains-not [e]{ is $v $e } $@argv }
|
||||
|
||||
fn reduce [v cb @argv]{
|
||||
each [e]{ v = ($cb $v $e) } (to-list $@argv)
|
||||
put $v
|
||||
|
|
@ -281,29 +284,28 @@ fn premove-duplicate [@argv]{ -premove-duplicate (-p $@argv) }
|
|||
fn swap [i j @argv]{ -swap $i $j (-p $@argv) }
|
||||
|
||||
fn -s1 [cb l e]{
|
||||
c = (count $l)
|
||||
i = (first-index [v]{ $cb $e $v } $l)
|
||||
local:c = (count $l)
|
||||
local:i = (first-index [v]{ $cb $e $v } $l)
|
||||
if (eq $i 0) {
|
||||
put $e
|
||||
explode $l
|
||||
all $l
|
||||
} elif (< $i 0) {
|
||||
explode $l
|
||||
all $l
|
||||
put $e
|
||||
} else {
|
||||
explode $l[:$i]
|
||||
all $l[:$i]
|
||||
put $e
|
||||
explode $l[{$i}:]
|
||||
all $l[{$i}:]
|
||||
}
|
||||
}
|
||||
|
||||
fn less [cb]{
|
||||
local:l = [a b]{ < ($cb $a $b) 0 }
|
||||
put $l
|
||||
}
|
||||
|
||||
fn -sort [cb l]{
|
||||
c = (count $l)
|
||||
if (> $c 1) {
|
||||
l2 = $l[:1]
|
||||
each [e]{ l2 = [ (-s1 $cb $l2 $e) ] } $l[1:]
|
||||
l = $l2
|
||||
}
|
||||
explode $l
|
||||
order &less-than=(less $cb) $l
|
||||
}
|
||||
|
||||
fn sort [cb @argv]{ -sort $cb (-p $@argv) }
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ fn value-of [container k &default=$nil]{
|
|||
fn unzip [container]{
|
||||
local:lkeys local:lvalues = [] []
|
||||
keys $container | each [k]{
|
||||
lkeys = [(explode $lkeys) $k]
|
||||
lvalues = [(explode $lvalues) $container[$k]]
|
||||
lkeys = [(all $lkeys) $k]
|
||||
lvalues = [(all $lvalues) $container[$k]]
|
||||
}
|
||||
put $lkeys $lvalues
|
||||
}
|
||||
|
|
@ -69,9 +69,24 @@ fn add [container key @values]{
|
|||
use ./list
|
||||
local:values = (list:to-list $values)
|
||||
if (has-key $container $key) {
|
||||
container[$key] = [(explode $container[$key]) $@values]
|
||||
container[$key] = [(all $container[$key]) $@values]
|
||||
} else {
|
||||
container[$key] = $values
|
||||
}
|
||||
put $container
|
||||
}
|
||||
|
||||
fn join [container container2]{
|
||||
keys $container2 | each [k]{
|
||||
container[$k] = $container2[$k]
|
||||
}
|
||||
put $container
|
||||
}
|
||||
|
||||
fn sorted-keys [&reverse=$false &less-than=$nil container]{
|
||||
keys $container | order &reverse=$reverse &less-than=$less-than
|
||||
}
|
||||
|
||||
fn sorted-values [&reverse=$false &less-than=$nil container]{
|
||||
values $container | order &reverse=$reverse &less-than=$less-than
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ fn -splitm [o]{ each [e]{ put -$e } $o[1:] }
|
|||
|
||||
fn -splitl [o]{
|
||||
if (str:contains $o '=') {
|
||||
local:opt @local:value = (splits '=' $o)
|
||||
local:opt @local:value = (str:split '=' $o)
|
||||
put $opt
|
||||
joins '=' $value
|
||||
str:join '=' $value
|
||||
} else {
|
||||
put $o
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ fn split [o]{
|
|||
}
|
||||
|
||||
fn -joins [opt]{
|
||||
local:o = (each [o]{ put $o[1:] } $opt | joins '')
|
||||
local:o = (each [o]{ put $o[1:] } $opt | str:join '')
|
||||
if (not-eq $o '') { put -$o }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue