maj de la configuration
This commit is contained in:
parent
df4f2c07c1
commit
2dac13303d
|
@ -0,0 +1,28 @@
|
||||||
|
#alias:new add_badips e:echo
|
||||||
|
fn add_badips [@_args]{
|
||||||
|
use moi/util/ip
|
||||||
|
use moi/util/list
|
||||||
|
use moi/util/map
|
||||||
|
use moi/util/number
|
||||||
|
use str
|
||||||
|
|
||||||
|
local:f = ~/bad_ips.txt
|
||||||
|
local:ips = [ (cat $f) ]
|
||||||
|
local:m = (map:to-set $ips)
|
||||||
|
local:c = 0
|
||||||
|
each [e]{
|
||||||
|
local:cond = (and (not (has-key $m $e)) (ip:is-ipv4 $e))
|
||||||
|
if $cond {
|
||||||
|
echo $e ajoutée
|
||||||
|
c = (number:++ $c)
|
||||||
|
m[$e] = $nil
|
||||||
|
ips = [ (all $ips) $e ]
|
||||||
|
}
|
||||||
|
} $_args
|
||||||
|
if (> $c 0) {
|
||||||
|
ips = [ (list:sort $ip:cmp4~ $ips) ]
|
||||||
|
}
|
||||||
|
local:result = (str:join "\n" $ips)
|
||||||
|
echo $result > $f
|
||||||
|
echo $c' IPs ajoutées ('(count $ips)' au total)'
|
||||||
|
}
|
|
@ -1,37 +1,36 @@
|
||||||
#alias:new clean_known_hosts e:cat
|
#alias:new clean_known_hosts e:cat
|
||||||
fn clean_known_hosts [@_args]{
|
fn clean_known_hosts [@_args]{
|
||||||
|
use str
|
||||||
use moi/util/condition
|
use moi/util/condition
|
||||||
use moi/util/list
|
use moi/util/list
|
||||||
use moi/util/ip
|
use moi/util/ip
|
||||||
fn less [cmp e1 e2]{ < ($cmp $e1 $e2) 0 }
|
fn less [cmp e1 e2]{ < ($cmp $e1 $e2) 0 }
|
||||||
fn sort-host [e1 e2]{
|
fn sort-host [e1 e2]{
|
||||||
local:i1 = (condition:set (ip:is-ipv4 $e1) 2 (condition:set (ip:is-ipv6 $e1) 1 0))
|
local:i1 = (condition:set (ip:is-ip $e1) 1 0)
|
||||||
local:i2 = (condition:set (ip:is-ipv4 $e2) 2 (condition:set (ip:is-ipv6 $e2) 1 0))
|
local:i2 = (condition:set (ip:is-ip $e2) 1 0)
|
||||||
if (!= $i1 $i2) {
|
if (!= $i1 $i2) {
|
||||||
< $i1 $i2
|
< $i1 $i2
|
||||||
} elif (== $i1 0) {
|
} elif (== $i1 0) {
|
||||||
<s $e1 $e2
|
<s $e1 $e2
|
||||||
} elif (== $i1 1) {
|
|
||||||
less $ip:cmp6~ $e1 $e2
|
|
||||||
} else {
|
} else {
|
||||||
less $ip:cmp4~ $e1 $e2
|
less $ip:cmp~ $e1 $e2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
local:khosts = [&]
|
local:khosts = [&]
|
||||||
cat ~/.ssh/known_hosts | eawk [_ hosts @rest]{
|
cat ~/.ssh/known_hosts | eawk [_ hosts @rest]{
|
||||||
local:key = (joins ' ' $rest)
|
local:key = (str:join ' ' $rest)
|
||||||
if (not (has-key $khosts $key)) {
|
if (not (has-key $khosts $key)) {
|
||||||
khosts[$key] = [&]
|
khosts[$key] = [&]
|
||||||
}
|
}
|
||||||
splits , $hosts | each [h]{
|
str:split , $hosts | each [h]{
|
||||||
khosts[$key][$h] = $nil
|
khosts[$key][$h] = $nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
local:lines = [(keys $khosts | each [key]{
|
local:lines = [(keys $khosts | each [key]{
|
||||||
local:hosts = (keys $khosts[$key] | list:sort $sort-host~ | joins ,)
|
local:hosts = (keys $khosts[$key] | order &less-than=$sort-host~ | str:join ,)
|
||||||
put $hosts $key | joins ' '
|
put $hosts $key | str:join ' '
|
||||||
})]
|
})]
|
||||||
echo (joins "\n" $lines) > ~/.ssh/known_hosts
|
echo (str:join "\n" $lines) > ~/.ssh/known_hosts
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
#alias:new dig e:dig +noall +answer
|
||||||
|
fn dig [@_args]{ e:dig +noall +answer $@_args }
|
|
@ -0,0 +1,69 @@
|
||||||
|
#alias:new digall e:dig ANY +noall +answer
|
||||||
|
fn digall [@_args]{
|
||||||
|
use moi/util/list
|
||||||
|
use str
|
||||||
|
|
||||||
|
local:default_records = [
|
||||||
|
A
|
||||||
|
AAAA
|
||||||
|
CNAME
|
||||||
|
PTR
|
||||||
|
TXT
|
||||||
|
MX
|
||||||
|
SRV
|
||||||
|
NAPTR
|
||||||
|
NS
|
||||||
|
SOA
|
||||||
|
]
|
||||||
|
local:records = []
|
||||||
|
local:servers = []
|
||||||
|
local:flags = [
|
||||||
|
+noall
|
||||||
|
+answer
|
||||||
|
]
|
||||||
|
local:domains = []
|
||||||
|
|
||||||
|
fn init []{
|
||||||
|
each [e]{
|
||||||
|
if (is $e[0] '+') {
|
||||||
|
flags = [ (all $flags) $e ]
|
||||||
|
} elif (is $e[0] @) {
|
||||||
|
servers = [ (all $servers) $e ]
|
||||||
|
} elif (list:includes $e $default_records) {
|
||||||
|
records = [ (all $records) $e ]
|
||||||
|
} else {
|
||||||
|
domains = [ (all $domains) $e ]
|
||||||
|
}
|
||||||
|
} $_args
|
||||||
|
if (== (count $records) 0) {
|
||||||
|
records = $default_records
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn digr [d @args]{
|
||||||
|
local:results = [ (each [r]{
|
||||||
|
e:dig $@args $r $d $@flags
|
||||||
|
} $records) ]
|
||||||
|
results = [ (list:remove-duplicate $results) ]
|
||||||
|
echo (str:join "\n" $results)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn digs [s d]{
|
||||||
|
echo (styled $s bright-yellow)
|
||||||
|
digr $d $s
|
||||||
|
}
|
||||||
|
|
||||||
|
fn digd [d]{
|
||||||
|
echo (styled 'Domaine: '$d bright-green)
|
||||||
|
if (> (count $servers) 0) {
|
||||||
|
each [s]{
|
||||||
|
digs $s $d
|
||||||
|
} $servers
|
||||||
|
} else {
|
||||||
|
digr $d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init
|
||||||
|
each $digd~ $domains
|
||||||
|
}
|
|
@ -3,7 +3,6 @@ fn ip-of [@_args]{
|
||||||
use str
|
use str
|
||||||
use moi/util/condition
|
use moi/util/condition
|
||||||
use moi/util/ip
|
use moi/util/ip
|
||||||
use moi/util/list
|
|
||||||
|
|
||||||
fn less [cmp e1 e2]{ < ($cmp $e1 $e2) 0 }
|
fn less [cmp e1 e2]{ < ($cmp $e1 $e2) 0 }
|
||||||
|
|
||||||
|
@ -79,7 +78,7 @@ fn ip-of [@_args]{
|
||||||
if (has-key $hosts $d) {
|
if (has-key $hosts $d) {
|
||||||
exists = $true
|
exists = $true
|
||||||
echo (styled ' local:' bright-yellow)
|
echo (styled ' local:' bright-yellow)
|
||||||
keys $hosts[$d] | list:sort $sort-ip~ | each [ip]{
|
keys $hosts[$d] | order &less-than=$sort-ip~ | each [ip]{
|
||||||
echo ' - '$ip
|
echo ' - '$ip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +87,7 @@ fn ip-of [@_args]{
|
||||||
local:info = $remote[$d]
|
local:info = $remote[$d]
|
||||||
echo (styled ' remote:' bright-yellow)
|
echo (styled ' remote:' bright-yellow)
|
||||||
echo ' IPs:'
|
echo ' IPs:'
|
||||||
keys $info[ips] | list:sort $sort-ip~ | each [ip]{
|
keys $info[ips] | order &less-than=$sort-ip~ | each [ip]{
|
||||||
echo ' - '$ip
|
echo ' - '$ip
|
||||||
}
|
}
|
||||||
echo ' Resolvers: '$info[resolvers]
|
echo ' Resolvers: '$info[resolvers]
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -11,6 +11,7 @@ alias:new cat bat -pp
|
||||||
alias:new midi e:fluidsynth -a pulseaudio /usr/share/soundfonts/FluidR3_GM.sf2
|
alias:new midi e:fluidsynth -a pulseaudio /usr/share/soundfonts/FluidR3_GM.sf2
|
||||||
alias:new timidity e:timidity -a -K -1
|
alias:new timidity e:timidity -a -K -1
|
||||||
alias:new git e:hub
|
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 pacmanhisto cat /var/log/pacman.log | grep "ALPM" | grep
|
||||||
alias:new pf e:pkgfile -vri
|
alias:new pf e:pkgfile -vri
|
||||||
|
|
|
@ -11,7 +11,7 @@ commands = [
|
||||||
|
|
||||||
extensions = [ tar bz2 zip gz lz4 sz xz zst rar ]
|
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]{
|
fn -comp-archive-files [m]{
|
||||||
local:type = (condition:set (eq $m '') prefix deep-prefix)
|
local:type = (condition:set (eq $m '') prefix deep-prefix)
|
||||||
|
|
|
@ -32,7 +32,7 @@ np = [
|
||||||
fn complete [@argv]{
|
fn complete [@argv]{
|
||||||
local:c = (count $argv)
|
local:c = (count $argv)
|
||||||
if (== $c 2) {
|
if (== $c 2) {
|
||||||
explode $options
|
all $options
|
||||||
} elif (and (== $c 3) (has-value $np $argv[-2])) {
|
} elif (and (== $c 3) (has-value $np $argv[-2])) {
|
||||||
-remotes-packages
|
-remotes-packages
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,14 @@ fn -repo-packages {
|
||||||
put $p
|
put $p
|
||||||
})]
|
})]
|
||||||
local:spackages = [&]
|
local:spackages = [&]
|
||||||
|
use str
|
||||||
peach [p]{
|
peach [p]{
|
||||||
splits '/' $p
|
str:split '/' $p
|
||||||
} $packages | peach [e]{
|
} $packages | peach [e]{
|
||||||
spackages[$e] = $nil
|
spackages[$e] = $nil
|
||||||
}
|
}
|
||||||
keys $spackages
|
keys $spackages
|
||||||
explode $packages
|
all $packages
|
||||||
}
|
}
|
||||||
|
|
||||||
fn -downloaded-packages [m]{
|
fn -downloaded-packages [m]{
|
||||||
|
@ -83,7 +84,7 @@ fpack = [
|
||||||
fn complete [@argv]{
|
fn complete [@argv]{
|
||||||
local:c = (count $argv)
|
local:c = (count $argv)
|
||||||
if (< $c 3) {
|
if (< $c 3) {
|
||||||
explode $options
|
all $options
|
||||||
} else {
|
} else {
|
||||||
local:cmd = $argv[1]
|
local:cmd = $argv[1]
|
||||||
if (and (== $c 3) (has-value $asdeps $cmd)) {
|
if (and (== $c 3) (has-value $asdeps $cmd)) {
|
||||||
|
|
|
@ -44,11 +44,11 @@ fn -init-hosts {
|
||||||
fn -init-known-hosts {
|
fn -init-known-hosts {
|
||||||
local:khosts = [&22=[&]]
|
local:khosts = [&22=[&]]
|
||||||
cat ~/.ssh/known_hosts | peach [l]{
|
cat ~/.ssh/known_hosts | peach [l]{
|
||||||
put [(splits ' ' $l)]
|
put [(str:split ' ' $l)]
|
||||||
} | peach [e]{
|
} | peach [e]{
|
||||||
local:domains @local:id = $@e
|
local:domains @local:id = $@e
|
||||||
id = (joins ' ' $id)
|
id = (str:join ' ' $id)
|
||||||
splits ',' $domains | peach [d]{
|
str:split ',' $domains | peach [d]{
|
||||||
local:d = $d
|
local:d = $d
|
||||||
local:port = 22
|
local:port = 22
|
||||||
if (eq $d[0] '[') {
|
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))) {
|
if (and (< $i $c) (or (and (eq $cmd ssh) (eq $arg -p)) (eq $arg -P))) {
|
||||||
port = $argv[(+ $i 1)]
|
port = $argv[(+ $i 1)]
|
||||||
} else {
|
} else {
|
||||||
local:nd = [(splits '@' $arg)]
|
local:nd = [(str:split '@' $arg)]
|
||||||
if (== (count $nd) 2) {
|
if (== (count $nd) 2) {
|
||||||
name = $nd[0]
|
name = $nd[0]
|
||||||
domain @_ = (splits ':' $nd[1])
|
domain @_ = (str:split ':' $nd[1])
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,14 +207,14 @@ fn -complete-args [cmd @argv]{
|
||||||
port = $port[-1]
|
port = $port[-1]
|
||||||
}
|
}
|
||||||
local:larg = $argv[-1]
|
local:larg = $argv[-1]
|
||||||
local:name @local:host = (splits '@' $larg)
|
local:name @local:host = (str:split '@' $larg)
|
||||||
if (list:empty $host) {
|
if (list:empty $host) {
|
||||||
-known-names &port=$port | each [n]{ put $n'@' }
|
-known-names &port=$port | each [n]{ put $n'@' }
|
||||||
if (eq $cmd 'scp') {
|
if (eq $cmd 'scp') {
|
||||||
file:match-files $larg
|
file:match-files $larg
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
host @_ = (splits ':' $host[0])
|
host @_ = (str:split ':' $host[0])
|
||||||
local:check = [h]{ has-prefix $h $host }
|
local:check = [h]{ has-prefix $h $host }
|
||||||
local:khosts = [(-known-hosts &port=$port &name=$name)]
|
local:khosts = [(-known-hosts &port=$port &name=$name)]
|
||||||
if (not (list:contains $check $khosts)) {
|
if (not (list:contains $check $khosts)) {
|
||||||
|
@ -224,7 +224,7 @@ fn -complete-args [cmd @argv]{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
each [h]{ put $name'@'$h } $khosts
|
each [h]{ put $name'@'$h } $khosts
|
||||||
explode $khosts
|
all $khosts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
fn complete [@argv]{
|
fn complete [@argv]{
|
||||||
if (and (> (count $argv) 2) (has-key $edit:completion:arg-completer $argv[1])) {
|
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 {
|
} else {
|
||||||
edit:complete-sudo $@argv
|
edit:complete-sudo $@argv
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -7,7 +7,7 @@ fn set [c t f]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mset [c t f]{
|
fn mset [c t f]{
|
||||||
explode (set $c $t $f)
|
all (set $c $t $f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call [c t f @argv]{
|
fn call [c t f @argv]{
|
||||||
|
|
|
@ -20,8 +20,7 @@ fn -less [f1 f2]{
|
||||||
|
|
||||||
fn -get-results [sort result]{
|
fn -get-results [sort result]{
|
||||||
if $sort {
|
if $sort {
|
||||||
use ./list
|
keys $result | order $-less~
|
||||||
keys $result | list:sort $-less~
|
|
||||||
} else {
|
} else {
|
||||||
keys $result
|
keys $result
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
fn is-ipv4 [arg]{
|
|
||||||
use re
|
use re
|
||||||
|
use str
|
||||||
|
|
||||||
|
fn is-ipv4 [arg]{
|
||||||
if (not (re:match '^([0-9]{1,3}\.){3}[0-9]{1,3}$' $arg)) {
|
if (not (re:match '^([0-9]{1,3}\.){3}[0-9]{1,3}$' $arg)) {
|
||||||
put $false
|
put $false
|
||||||
} else {
|
} else {
|
||||||
use ./list
|
use ./list
|
||||||
not (splits '.' $arg | list:contains [p]{ > $p 255 })
|
not (str:split '.' $arg | list:contains [p]{ > $p 255 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is-ipv6 [arg]{
|
fn is-ipv6 [arg]{
|
||||||
use re
|
|
||||||
local:p = '[0-9a-fA-F]{1,4}'
|
local:p = '[0-9a-fA-F]{1,4}'
|
||||||
local:g1 local:g2 = '('$p':)' '(:'$p')'
|
local:g1 local:g2 = '('$p':)' '(:'$p')'
|
||||||
local:cases = [
|
local:cases = [
|
||||||
|
@ -24,15 +25,17 @@ fn is-ipv6 [arg]{
|
||||||
':'$g2'{1,7}'
|
':'$g2'{1,7}'
|
||||||
'::'
|
'::'
|
||||||
]
|
]
|
||||||
local:r = '^('(joins '|' $cases)')$'
|
local:r = '^('(str:join '|' $cases)')$'
|
||||||
put (re:match $r $arg)
|
put (re:match $r $arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
p = (str:to-lower $p)
|
||||||
c = (- 4 (count $p))
|
c = (- 4 (count $p))
|
||||||
put (repeat $c '0' | joins '')$p
|
put (repeat $c '0' | str:join '')$p
|
||||||
}
|
}
|
||||||
|
|
||||||
fn -middle-part6 [p]{
|
fn -middle-part6 [p]{
|
||||||
|
@ -68,25 +71,24 @@ fn long6 [ip]{
|
||||||
fail 'Not an IPv6'
|
fail 'Not an IPv6'
|
||||||
}
|
}
|
||||||
if (eq $ip '::') {
|
if (eq $ip '::') {
|
||||||
repeat 8 '0000' | joins ':'
|
repeat 8 '0000' | str:join ':'
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
use str
|
|
||||||
local:c = (- 7 (str:count $ip ':'))
|
local:c = (- 7 (str:count $ip ':'))
|
||||||
if (> $c 0) {
|
if (> $c 0) {
|
||||||
local:i = (str:index $ip '::')
|
local:i = (str:index $ip '::')
|
||||||
local:z = (repeat $c ':' | joins '')
|
local:z = (repeat $c ':' | str:join '')
|
||||||
ip = (joins '' [$ip[:$i] $z $ip[{$i}:]])
|
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]{
|
fn middle6 [ip]{
|
||||||
splits ':' (long6 $ip) | each $-middle-part6~ | joins ':'
|
str:split ':' (long6 $ip) | each $-middle-part6~ | str:join ':'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn short6 [ip]{
|
fn short6 [ip]{
|
||||||
local:parts = [(splits ':' (middle6 $ip))]
|
local:parts = [(str:split ':' (middle6 $ip))]
|
||||||
local:i local:s = (-find-max0 $parts)
|
local:i local:s = (-find-max0 $parts)
|
||||||
if (>= $i 0) {
|
if (>= $i 0) {
|
||||||
local:left local:right = $parts[:$i] $parts[(+ $i $s):]
|
local:left local:right = $parts[:$i] $parts[(+ $i $s):]
|
||||||
|
@ -98,7 +100,7 @@ fn short6 [ip]{
|
||||||
}
|
}
|
||||||
parts = [$@left '' $@right]
|
parts = [$@left '' $@right]
|
||||||
}
|
}
|
||||||
joins ':' $parts
|
str:join ':' $parts
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is-ip [arg]{ or (is-ipv4 $arg) (is-ipv6 $arg) }
|
fn is-ip [arg]{ or (is-ipv4 $arg) (is-ipv6 $arg) }
|
||||||
|
@ -119,14 +121,34 @@ fn -cmp [e1 e2]{
|
||||||
|
|
||||||
fn cmp4 [ip1 ip2]{
|
fn cmp4 [ip1 ip2]{
|
||||||
if (or (not (is-ipv4 $ip1)) (not (is-ipv4 $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]{
|
fn cmp6 [ip1 ip2]{
|
||||||
if (or (not (is-ipv6 $ip1)) (not (is-ipv6 $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'
|
fail 'Index out of range'
|
||||||
}
|
}
|
||||||
if (eq $i $j) {
|
if (eq $i $j) {
|
||||||
explode $l
|
all $l
|
||||||
} else {
|
} else {
|
||||||
i j = (condition:mset (< $i $j) [$i $j] [$j $i])
|
i j = (condition:mset (< $i $j) [$i $j] [$j $i])
|
||||||
take $i $l
|
take $i $l
|
||||||
put $l[j]
|
put $l[j]
|
||||||
explode $l[(+ $i 1):$j]
|
all $l[(+ $i 1):$j]
|
||||||
put $l[$i]
|
put $l[$i]
|
||||||
drop (+ $j 1) $l
|
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 [cb @argv]{ -exists $cb (-p $@argv) }
|
||||||
fn exists-not [cb @argv]{ exists [i v]{ $cb $i $v } $@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]{
|
fn reduce [v cb @argv]{
|
||||||
each [e]{ v = ($cb $v $e) } (to-list $@argv)
|
each [e]{ v = ($cb $v $e) } (to-list $@argv)
|
||||||
put $v
|
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 swap [i j @argv]{ -swap $i $j (-p $@argv) }
|
||||||
|
|
||||||
fn -s1 [cb l e]{
|
fn -s1 [cb l e]{
|
||||||
c = (count $l)
|
local:c = (count $l)
|
||||||
i = (first-index [v]{ $cb $e $v } $l)
|
local:i = (first-index [v]{ $cb $e $v } $l)
|
||||||
if (eq $i 0) {
|
if (eq $i 0) {
|
||||||
put $e
|
put $e
|
||||||
explode $l
|
all $l
|
||||||
} elif (< $i 0) {
|
} elif (< $i 0) {
|
||||||
explode $l
|
all $l
|
||||||
put $e
|
put $e
|
||||||
} else {
|
} else {
|
||||||
explode $l[:$i]
|
all $l[:$i]
|
||||||
put $e
|
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]{
|
fn -sort [cb l]{
|
||||||
c = (count $l)
|
order &less-than=(less $cb) $l
|
||||||
if (> $c 1) {
|
|
||||||
l2 = $l[:1]
|
|
||||||
each [e]{ l2 = [ (-s1 $cb $l2 $e) ] } $l[1:]
|
|
||||||
l = $l2
|
|
||||||
}
|
|
||||||
explode $l
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sort [cb @argv]{ -sort $cb (-p $@argv) }
|
fn sort [cb @argv]{ -sort $cb (-p $@argv) }
|
||||||
|
|
|
@ -14,8 +14,8 @@ fn value-of [container k &default=$nil]{
|
||||||
fn unzip [container]{
|
fn unzip [container]{
|
||||||
local:lkeys local:lvalues = [] []
|
local:lkeys local:lvalues = [] []
|
||||||
keys $container | each [k]{
|
keys $container | each [k]{
|
||||||
lkeys = [(explode $lkeys) $k]
|
lkeys = [(all $lkeys) $k]
|
||||||
lvalues = [(explode $lvalues) $container[$k]]
|
lvalues = [(all $lvalues) $container[$k]]
|
||||||
}
|
}
|
||||||
put $lkeys $lvalues
|
put $lkeys $lvalues
|
||||||
}
|
}
|
||||||
|
@ -69,9 +69,24 @@ fn add [container key @values]{
|
||||||
use ./list
|
use ./list
|
||||||
local:values = (list:to-list $values)
|
local:values = (list:to-list $values)
|
||||||
if (has-key $container $key) {
|
if (has-key $container $key) {
|
||||||
container[$key] = [(explode $container[$key]) $@values]
|
container[$key] = [(all $container[$key]) $@values]
|
||||||
} else {
|
} else {
|
||||||
container[$key] = $values
|
container[$key] = $values
|
||||||
}
|
}
|
||||||
put $container
|
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]{
|
fn -splitl [o]{
|
||||||
if (str:contains $o '=') {
|
if (str:contains $o '=') {
|
||||||
local:opt @local:value = (splits '=' $o)
|
local:opt @local:value = (str:split '=' $o)
|
||||||
put $opt
|
put $opt
|
||||||
joins '=' $value
|
str:join '=' $value
|
||||||
} else {
|
} else {
|
||||||
put $o
|
put $o
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ fn split [o]{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn -joins [opt]{
|
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 }
|
if (not-eq $o '') { put -$o }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
rc.elv
5
rc.elv
|
@ -54,7 +54,10 @@ paths = [$@paths ~/bin $E:GOPATH/bin ]
|
||||||
|
|
||||||
-exports- = (aliases:export)
|
-exports- = (aliases:export)
|
||||||
|
|
||||||
fn dcd [@_args]{ cmd = (aliases:export); $cmd[br~] --only-folders --cmd (joins ' ' $_args)' :cd' }
|
fn dcd [@_args]{
|
||||||
|
use str
|
||||||
|
cmd = (aliases:export); $cmd[br~] --only-folders --cmd (str:join ' ' $_args)' :cd'
|
||||||
|
}
|
||||||
|
|
||||||
tache search -d 2w not del
|
tache search -d 2w not del
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue