Préparation à elvish 0.17

This commit is contained in:
Benjamin VAUDOUR 2021-10-13 20:43:40 +02:00
parent 4170890f54
commit 08d0e16cff
11 changed files with 47 additions and 47 deletions

View File

@ -11,13 +11,13 @@ edit:add-var addbadips~ [@argv]{
var cond = (and (not (has-key $m $e)) (ip:is-ipv4 $e)) var cond = (and (not (has-key $m $e)) (ip:is-ipv4 $e))
if $cond { if $cond {
echo $e ajoutée echo $e ajoutée
c = (+ $c 1) set c = (+ $c 1)
m[$e] = $nil set m[$e] = $nil
ips = [ (all $ips) $e ] set ips = [ (all $ips) $e ]
} }
} $argv } $argv
if (> $c 0) { if (> $c 0) {
ips = [ (list:sort $ip:cmp4~ $ips) ] set ips = [ (list:sort $ip:cmp4~ $ips) ]
} }
var result = (str:join "\n" $ips) var result = (str:join "\n" $ips)
echo $result > $f echo $result > $f

View File

@ -4,7 +4,7 @@ edit:add-var adguard~ [@argv]{
var beg = 's|^.*\(192\.168\.0\.25\)|' var beg = 's|^.*\(192\.168\.0\.25\)|'
var end = 'nameserver \1|' var end = 'nameserver \1|'
if (and (> (count $argv) 0) (str:has-prefix $argv[0] u)) { if (and (> (count $argv) 0) (str:has-prefix $argv[0] u)) {
end = '# '$end set end = '# '$end
} }
sudo sed -i $beg$end /etc/resolv.conf sudo sed -i $beg$end /etc/resolv.conf
sudo chattr +i /etc/resolv.conf sudo chattr +i /etc/resolv.conf

View File

@ -4,7 +4,7 @@ edit:add-var curl~ $e:curlie~
edit:add-var df~ $e:duf~ edit:add-var df~ $e:duf~
edit:add-var diff~ $e:colordiff~ edit:add-var diff~ $e:colordiff~
edit:add-var dig~ [@argv]{ e:dig +noall +answer $@argv } edit:add-var dig~ [@argv]{ e:dig +noall +answer $@argv }
edit:add-var dogall~ [@argv]{ e:dog A AAAA CNAME PTR TXT MX SRV NS SOA $@argv } edit:add-var dogall~ [@argv]{ e:dog A AAAA CNAME TXT MX NS SOA $@argv }
edit:add-var du~ [@argv]{ e:du -h $@argv } edit:add-var du~ [@argv]{ e:du -h $@argv }
edit:add-var git~ $e:hub~ edit:add-var git~ $e:hub~
edit:add-var grep~ [@argv]{ e:grep --color=tty -d skip $@argv } edit:add-var grep~ [@argv]{ e:grep --color=tty -d skip $@argv }

View File

@ -1,8 +1,8 @@
cmd = $e:arc~ var cmd = $e:arc~
edit:add-var archiver~ [@argv]{ edit:add-var archiver~ [@argv]{
use str use str
help = { var help = {
echo "Usage : archiver [(-zlxgb)] <file to compress>" echo "Usage : archiver [(-zlxgb)] <file to compress>"
return return
} }
@ -11,7 +11,7 @@ edit:add-var archiver~ [@argv]{
} }
var format o = zst $argv[0] var format o = zst $argv[0]
if (and (str:has-prefix $o -) (> (count $o) 1)) { if (and (str:has-prefix $o -) (> (count $o) 1)) {
o = $o[1] set o = $o[1]
var m = [ var m = [
&z=zst &z=zst
&l=lz4 &l=lz4
@ -22,7 +22,7 @@ edit:add-var archiver~ [@argv]{
if (not (has-key $m $o)) { if (not (has-key $m $o)) {
$help $help
} }
format argv = $m[$o] $argv[1..] set format argv = $m[$o] $argv[1..]
} }
if (== (count $argv) 0) { if (== (count $argv) 0) {
$help $help
@ -30,7 +30,7 @@ edit:add-var archiver~ [@argv]{
peach [f]{ peach [f]{
var ff = $f var ff = $f
if (eq $ff[-1] /) { if (eq $ff[-1] /) {
f = $ff[..-1] set f = $ff[..-1]
} }
$cmd archive $ff'.tar.'$format $ff $cmd archive $ff'.tar.'$format $ff
echo "'"$ff"'" archivé echo "'"$ff"'" archivé

View File

@ -20,10 +20,10 @@ edit:add-var cleankh~ [@argv]{
cat ~/.ssh/known_hosts | eawk [_ hosts @rest]{ cat ~/.ssh/known_hosts | eawk [_ hosts @rest]{
var key = (str:join ' ' $rest) var key = (str:join ' ' $rest)
if (not (has-key $khosts $key)) { if (not (has-key $khosts $key)) {
khosts[$key] = [&] set khosts[$key] = [&]
} }
str:split , $hosts | each [h]{ str:split , $hosts | each [h]{
khosts[$key][$h] = $nil set khosts[$key][$h] = $nil
} }
} }

View File

@ -7,12 +7,12 @@ edit:add-var commitkcp~ [@argv]{
keys $m | each [k]{ keys $m | each [k]{
var p = 'pkg'$k'=' var p = 'pkg'$k'='
m[$k] = (str:trim-prefix (cat PKGBUILD | grep $p | take 1) $p) set m[$k] = (str:trim-prefix (cat PKGBUILD | grep $p | take 1) $p)
} }
var msg = $m[name]' '$m[ver] var msg = $m[name]' '$m[ver]
if (> (count $argv) 0) { if (> (count $argv) 0) {
msg = $msg' - '(str:join ' ' $argv) set msg = $msg' - '(str:join ' ' $argv)
} }
echo "git commit -am '"$msg"' ; git push" echo "git commit -am '"$msg"' ; git push"

View File

@ -29,22 +29,22 @@ edit:add-var digall~ [@argv]{
fn init []{ fn init []{
if (and (> (count $argv) 0) (is $argv[0] -d)) { if (and (> (count $argv) 0) (is $argv[0] -d)) {
use_dig = $false set use_dig = $false
argv = $argv[1:] set argv = $argv[1:]
} }
each [e]{ each [e]{
if (is $e[0] '+') { if (is $e[0] '+') {
flags = [ (all $flags) $e ] set flags = [ (all $flags) $e ]
} elif (is $e[0] @) { } elif (is $e[0] @) {
servers = [ (all $servers) $e ] set servers = [ (all $servers) $e ]
} elif (list:includes $e $default_records) { } elif (list:includes $e $default_records) {
records = [ (all $records) $e ] set records = [ (all $records) $e ]
} else { } else {
domains = [ (all $domains) $e ] set domains = [ (all $domains) $e ]
} }
} $argv } $argv
if (== (count $records) 0) { if (== (count $records) 0) {
records = $default_records set records = $default_records
} }
} }
@ -54,7 +54,7 @@ edit:add-var digall~ [@argv]{
} $results | list:remove-duplicate | list:sort [l1 l2]{ } $results | list:remove-duplicate | list:sort [l1 l2]{
var c = (str:compare $l1[0] $l2[0]) var c = (str:compare $l1[0] $l2[0])
if (== $c 0) { if (== $c 0) {
c = (str:compare $l1[2] $l2[2]) set c = (str:compare $l1[2] $l2[2])
} }
} | strutil:format &col=$cols | str:join "\n" } | strutil:format &col=$cols | str:join "\n"
} }
@ -92,10 +92,10 @@ edit:add-var digall~ [@argv]{
var results = [ (echo (styled 'Domaine: '$d bright-green)) ] var results = [ (echo (styled 'Domaine: '$d bright-green)) ]
if (> (count $servers) 0) { if (> (count $servers) 0) {
each [s]{ each [s]{
@results = $@results (digs $s $d) set @results = $@results (digs $s $d)
} $servers } $servers
} else { } else {
@results = $@results (req $d) set @results = $@results (req $d)
} }
echo (str:join "\n" $results) echo (str:join "\n" $results)
} }

View File

@ -25,7 +25,7 @@ fn -get-id []{
str:split ' ' (id) | each [e]{ str:split ' ' (id) | each [e]{
var p = [ (str:split '=' $e) ] var p = [ (str:split '=' $e) ]
if (== (count $p) 2) { if (== (count $p) 2) {
id[$p[0]] = (-values $p[1]) set id[$p[0]] = (-values $p[1])
} }
} }
put $id put $id

View File

@ -33,15 +33,15 @@ edit:add-var ipof~ [@argv]{
str:split ', ' $value | peach [e]{ str:split ', ' $value | peach [e]{
var ee = $e var ee = $e
if (ip:is-ip $ee) { if (ip:is-ip $ee) {
result[ips][$ee] = $nil set result[ips][$ee] = $nil
} }
} }
} elif (str:has-prefix $ll 'TXT records') { } elif (str:has-prefix $ll 'TXT records') {
result[txt] = $value set result[txt] = $value
} elif (str:has-prefix $ll 'Resolver') { } elif (str:has-prefix $ll 'Resolver') {
result[resolvers] = $value set result[resolvers] = $value
} elif (str:has-prefix $ll 'Name servers') { } elif (str:has-prefix $ll 'Name servers') {
result[remote] = (not-eq $value 'name does not exist') set result[remote] = (not-eq $value 'name does not exist')
} }
} }
put $result put $result
@ -57,9 +57,9 @@ edit:add-var ipof~ [@argv]{
peach [d]{ peach [d]{
var dd = $d var dd = $d
if (has-key $hosts $dd) { if (has-key $hosts $dd) {
hosts[$dd][$ip] = $nil set hosts[$dd][$ip] = $nil
} else { } else {
hosts[$dd] = [&$ip=$nil] set hosts[$dd] = [&$ip=$nil]
} }
} $domains } $domains
} }
@ -69,7 +69,7 @@ edit:add-var ipof~ [@argv]{
var dd = $d var dd = $d
var solve = (dnssolve $dd) var solve = (dnssolve $dd)
if (> (keys $solve[ips] | count) 0) { if (> (keys $solve[ips] | count) 0) {
remote[$dd] = $solve set remote[$dd] = $solve
} }
} $argv } $argv
@ -78,14 +78,14 @@ edit:add-var ipof~ [@argv]{
echo (styled 'Resolving '$d'…' bright-green) echo (styled 'Resolving '$d'…' bright-green)
echo echo
if (has-key $hosts $d) { if (has-key $hosts $d) {
exists = $true set exists = $true
echo (styled ' local:' bright-yellow) echo (styled ' local:' bright-yellow)
keys $hosts[$d] | order &less-than=$sort-ip~ | each [ip]{ keys $hosts[$d] | order &less-than=$sort-ip~ | each [ip]{
echo ' - '$ip echo ' - '$ip
} }
} }
if (and (has-key $remote $d) $remote[$d][remote]) { if (and (has-key $remote $d) $remote[$d][remote]) {
exists = $true set exists = $true
var info = $remote[$d] var info = $remote[$d]
echo (styled ' remote:' bright-yellow) echo (styled ' remote:' bright-yellow)
echo ' IPs:' echo ' IPs:'

View File

@ -32,15 +32,15 @@ edit:add-var pdf2grey~ [@argv]{
_help _help
return return
} elif (eq $e -n) { } elif (eq $e -n) {
m[nb] = $true set m[nb] = $true
if (== (count $e) 0) { if (== (count $e) 0) {
echo 'Il manque des arguments après -s' echo 'Il manque des arguments après -s'
_help _help
return return
} elif (is_int $argv[0]) { } elif (is_int $argv[0]) {
e @argv = $@argv set e @argv = $@argv
if (is_split $e) { if (is_split $e) {
m[split] = $e set m[split] = $e
} else { } else {
echo 'Largument (optionnel) après -s doit être compris entre 0 et 100' echo 'Largument (optionnel) après -s doit être compris entre 0 et 100'
_help _help
@ -52,9 +52,9 @@ edit:add-var pdf2grey~ [@argv]{
_help _help
return return
} elif (not (has-key $m input)) { } elif (not (has-key $m input)) {
m[input] = $e set m[input] = $e
} else { } else {
m[output] = $e set m[output] = $e
if (> (count $argv) 0) { if (> (count $argv) 0) {
echo 'Trop darguments: '$@argv echo 'Trop darguments: '$@argv
_help _help
@ -74,9 +74,9 @@ edit:add-var pdf2grey~ [@argv]{
var params = [-colorspace gray] var params = [-colorspace gray]
if $m[nb] { if $m[nb] {
@params = (all $params) -threshold $m[split]'%' set @params = (all $params) -threshold $m[split]'%'
} }
@params = $@params $m[input] $m[output] set @params = $@params $m[input] $m[output]
echo 'Commande: convert '(str:join ' ' $params) echo 'Commande: convert '(str:join ' ' $params)
convert $@params convert $@params
} }

View File

@ -1,8 +1,8 @@
edit:add-var publicip~ [@argv]{ edit:add-var publicip~ [@argv]{
f = [t]{ var f = [t]{
use moi/util/condition use moi/util/condition
t = (condition:cset (eq $t -6) -6 -4) set t = (condition:cset (eq $t -6) -6 -4)
l = (condition:cset (eq $t -6) 'IPv6: ' 'IPv4: ') var l = (condition:cset (eq $t -6) 'IPv6: ' 'IPv4: ')
curl $t ifconfig.co/ip 2> /dev/null | each [ip]{ echo (styled $l bold yellow) $ip } curl $t ifconfig.co/ip 2> /dev/null | each [ip]{ echo (styled $l bold yellow) $ip }
} }
$f -4 $f -4