Fusion des commandes liées à arc en un seul fichier + renommage local:variable par var variable pour plus de lisibilité

This commit is contained in:
Benjamin VAUDOUR 2021-08-27 21:45:39 +02:00
parent 62ebf74ebe
commit 81ab7d87ed
15 changed files with 78 additions and 81 deletions

View File

@ -4,12 +4,11 @@ edit:add-var addbadips~ [@argv]{
use moi/util/map
use str
local:f = ~/bad_ips.txt
local:ips = [ (cat $f) ]
local:m = (map:to-set $ips)
local:c = 0
var f = ~/bad_ips.txt
var ips = [ (cat $f) ]
var m c = (map:to-set $ips) 0
each [e]{
local: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 {
echo $e ajoutée
c = (+ $c 1)
@ -20,7 +19,7 @@ edit:add-var addbadips~ [@argv]{
if (> $c 0) {
ips = [ (list:sort $ip:cmp4~ $ips) ]
}
local:result = (str:join "\n" $ips)
var result = (str:join "\n" $ips)
echo $result > $f
echo $c' IPs ajoutées ('(count $ips)' au total)'
}

View File

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

View File

@ -1,3 +1,5 @@
cmd = $e:arc~
edit:add-var archiver~ [@argv]{
use str
help = {
@ -7,11 +9,10 @@ edit:add-var archiver~ [@argv]{
if (or (== (count $argv) 0) (eq $argv[0] -h)) {
$help
}
local:format = zst
local:o = $argv[0]
var format o = zst $argv[0]
if (and (str:has-prefix $o -) (> (count $o) 1)) {
o = $o[1]
local:m = [
var m = [
&z=zst
&l=lz4
&x=xz
@ -21,19 +22,32 @@ edit:add-var archiver~ [@argv]{
if (not (has-key $m $o)) {
$help
}
format = $m[$o]
argv = $argv[1..]
format argv = $m[$o] $argv[1..]
}
if (== (count $argv) 0) {
$help
}
peach [f]{
local:f = $f
var f = $f
if (eq $f[-1] /) {
f = $f[..-1]
}
e:arc archive $f'.tar.'$format $f
$cmd archive $f'.tar.'$format $f
echo "'"$f"'" archivé
} $argv
}
edit:add-var desarchiver~ [@argv]{
peach [f]{
var f = $f
$cmd unarchive $f
echo "'"$f"'" désarchivé
} $argv
}
edit:add-var listarchiver~ [@argv]{
peach [f]{
local f = $f
$cmd ls $f
} $argv
}

View File

@ -5,8 +5,8 @@ edit:add-var cleankh~ [@argv]{
use moi/util/ip
fn less [cmp e1 e2]{ < ($cmp $e1 $e2) 0 }
fn sort-host [e1 e2]{
local:i1 = (condition:cset (ip:is-ip $e1) 1 0)
local:i2 = (condition:cset (ip:is-ip $e2) 1 0)
var i1 = (condition:cset (ip:is-ip $e1) 1 0)
var i2 = (condition:cset (ip:is-ip $e2) 1 0)
if (!= $i1 $i2) {
< $i1 $i2
} elif (== $i1 0) {
@ -16,9 +16,9 @@ edit:add-var cleankh~ [@argv]{
}
}
local:khosts = [&]
var khosts = [&]
cat ~/.ssh/known_hosts | eawk [_ hosts @rest]{
local:key = (str:join ' ' $rest)
var key = (str:join ' ' $rest)
if (not (has-key $khosts $key)) {
khosts[$key] = [&]
}
@ -27,8 +27,8 @@ edit:add-var cleankh~ [@argv]{
}
}
local:lines = [(keys $khosts | each [key]{
local:hosts = (keys $khosts[$key] | order &less-than=$sort-host~ | str:join ,)
var lines = [(keys $khosts | each [key]{
var hosts = (keys $khosts[$key] | order &less-than=$sort-host~ | str:join ,)
put $hosts $key | str:join ' '
})]
echo (str:join "\n" $lines) > ~/.ssh/known_hosts

View File

@ -1,16 +1,16 @@
edit:add-var commitkcp~ [@argv]{
use str
local:m = [
var m = [
&name=
&ver=
]
keys $m | each [k]{
local:p = 'pkg'$k'='
var p = 'pkg'$k'='
m[$k] = (str:trim-prefix (cat PKGBUILD | grep $p | take 1) $p)
}
local:msg = $m[name]' '$m[ver]
var msg = $m[name]' '$m[ver]
if (> (count $argv) 0) {
msg = $msg' - '(str:join ' ' $argv)
}

View File

@ -1,8 +0,0 @@
edit:add-var desarchiver~ [@argv]{
peach [f]{
local:f = $f
e:arc unarchive $f
echo "'"$f"'" désarchivé
} $argv
}

View File

@ -3,7 +3,7 @@ edit:add-var digall~ [@argv]{
use moi/util/strutil
use str
local:default_records = [
var default_records = [
A
AAAA
CNAME
@ -15,19 +15,17 @@ edit:add-var digall~ [@argv]{
NS
SOA
]
local:cols = [
var cols = [
[&min=24]
[&min=8]
[&min=10]
]
local:records = []
local:servers = []
local:flags = [
var records servers = [] []
var flags = [
+noall
+answer
]
local:domains = []
local:use_dig = $true
var domains use_dig = [] $true
fn init []{
if (and (> (count $argv) 0) (is $argv[0] -d)) {
@ -54,7 +52,7 @@ edit:add-var digall~ [@argv]{
eawk [_ @args]{
put [ $args[0] (all $args[2..]) ]
} $results | list:remove-duplicate | list:sort [l1 l2]{
local:c = (str:compare $l1[0] $l2[0])
var c = (str:compare $l1[0] $l2[0])
if (== $c 0) {
c = (str:compare $l1[2] $l2[2])
}
@ -62,7 +60,7 @@ edit:add-var digall~ [@argv]{
}
fn drillr [d @args]{
local:results = [ (peach [r]{
var results = [ (peach [r]{
e:drill $@args $r $d | list:filter [e]{
and (> (count $e) 2) (not (is $e[:2] ';;'))
}
@ -71,7 +69,7 @@ edit:add-var digall~ [@argv]{
}
fn digr [d @args]{
local:results = [ (peach [r]{
var results = [ (peach [r]{
e:dig $@args $r $d $@flags
} $records) ]
format $results
@ -91,7 +89,7 @@ edit:add-var digall~ [@argv]{
}
fn digd [d]{
local:results = [ (echo (styled 'Domaine: '$d bright-green)) ]
var results = [ (echo (styled 'Domaine: '$d bright-green)) ]
if (> (count $servers) 0) {
each [s]{
@results = $@results (digs $s $d)

View File

@ -2,7 +2,7 @@ use re
use str
fn -value [v]{
local:p = (re:find '^(\d+)\((\w+)\)$' $v)
var p = (re:find '^(\d+)\((\w+)\)$' $v)
if (and (has-key $p groups) (== (count $p[groups]) 3)) {
put [
&number=$p[groups][1][text]
@ -12,7 +12,7 @@ fn -value [v]{
}
fn -values [v]{
local:vv = [ (str:split ',' $v) ]
var vv = [ (str:split ',' $v) ]
if (== (count $vv) 1) {
-value $vv[0]
} else {
@ -21,9 +21,9 @@ fn -values [v]{
}
fn -get-id []{
local:id = [&]
var id = [&]
str:split ' ' (id) | each [e]{
local:p = [ (str:split '=' $e) ]
var p = [ (str:split '=' $e) ]
if (== (count $p) 2) {
id[$p[0]] = (-values $p[1])
}
@ -32,7 +32,7 @@ fn -get-id []{
}
fn -get [k]{
local:id = (-get-id)
var id = (-get-id)
if (has-key $id $k) {
put $id[$k]
}

View File

@ -2,7 +2,7 @@ edit:add-var ipinfo~ [@argv]{
use moi/util/ip
use str
local:token = (cat $E:HOME/.config/elvish/private/ipinfo_token)
var token = (cat $E:HOME/.config/elvish/private/ipinfo_token)
fn url-of [ip]{
str:join '' [ 'ipinfo.io/' $ip '?token=' $token]
@ -10,7 +10,7 @@ edit:add-var ipinfo~ [@argv]{
fn info [ip]{
if (ip:is-ip $ip) {
local:url = (url-of $ip)
var url = (url-of $ip)
echo 'URL: '$url
e:curlie $url
}

View File

@ -6,8 +6,8 @@ edit:add-var ipof~ [@argv]{
fn less [cmp e1 e2]{ < ($cmp $e1 $e2) 0 }
fn sort-ip [e1 e2]{
local:i1 = (condition:cset (ip:is-ipv4 $e1) 0 (condition:cset (ip:is-ipv6 $e1) 1 2))
local:i2 = (condition:cset (ip:is-ipv4 $e2) 0 (condition:cset (ip:is-ipv6 $e2) 1 2))
var i1 = (condition:cset (ip:is-ipv4 $e1) 0 (condition:cset (ip:is-ipv6 $e1) 1 2))
var i2 = (condition:cset (ip:is-ipv4 $e2) 0 (condition:cset (ip:is-ipv6 $e2) 1 2))
if (!= $i1 $i2) {
< $i1 $i2
} elif (== $i1 2) {
@ -20,18 +20,18 @@ edit:add-var ipof~ [@argv]{
}
fn dnssolve [d]{
local:result = [
var result = [
&ips=[&]
&resolvers=''
&txt=''
]
e:dnscrypt-proxy -config /etc/dnscrypt-proxy/dnscrypt-proxy.toml -resolve (idn -a $d) | peach [l]{
local:l = $l
local:idx = (+ (str:index $l :) 1)
local:value = (str:trim-space $l[$idx".."])
var l = $l
var idx = (+ (str:index $l :) 1)
var value = (str:trim-space $l[$idx".."])
if (or (str:has-prefix $l 'IPv4 addresses') (str:has-prefix $l 'IPv6 addresses')) {
str:split ', ' $value | peach [e]{
local:e = $e
var e = $e
if (ip:is-ip $e) {
result[ips][$e] = $nil
}
@ -47,16 +47,16 @@ edit:add-var ipof~ [@argv]{
put $result
}
local:hosts = [&]
var hosts = [&]
cat /etc/hosts | peach [l]{
local:l = $l
var l = $l
l = (str:trim-space $l)
if (and (not-eq $l '') (not-eq $l[0] '#')) {
put $l
}
} | eawk [_ ip @domains]{
peach [d]{
local:d = $d
var d = $d
if (has-key $hosts $d) {
hosts[$d][$ip] = $nil
} else {
@ -65,17 +65,17 @@ edit:add-var ipof~ [@argv]{
} $domains
}
local:remote = [&]
var remote = [&]
peach [d]{
local:d = $d
local:solve = (dnssolve $d)
var d = $d
var solve = (dnssolve $d)
if (> (keys $solve[ips] | count) 0) {
remote[$d] = $solve
}
} $argv
each [d]{
local:exists = $false
var exists = $false
echo (styled 'Resolving '$d'…' bright-green)
echo
if (has-key $hosts $d) {
@ -87,7 +87,7 @@ edit:add-var ipof~ [@argv]{
}
if (and (has-key $remote $d) $remote[$d][remote]) {
exists = $true
local:info = $remote[$d]
var info = $remote[$d]
echo (styled ' remote:' bright-yellow)
echo ' IPs:'
keys $info[ips] | order &less-than=$sort-ip~ | each [ip]{

View File

@ -1,6 +0,0 @@
edit:add-var listarchiver~ [@argv]{
peach [f]{
local:f = $f
e:arc ls $f
} $argv
}

View File

@ -6,7 +6,7 @@ fn -go-ls [@argv]{
e:go-ls --group-directories-first -T '+%Y.%m.%d %H:%M' --git $@argv
}
local:cmd = $-go-ls~
var cmd = $-go-ls~
edit:add-var ls~ [@argv]{ $cmd $@argv }
edit:add-var la~ [@argv]{ $cmd -a $@argv }

View File

@ -1,7 +1,7 @@
edit:add-var pdf2grey~ [@argv]{
use re
use str
local:m = [
var m = [
&nb=$false
&split=50
]
@ -27,7 +27,7 @@ edit:add-var pdf2grey~ [@argv]{
}
while (> (count $argv) 0) {
local:e @argv = $@argv
var e @argv = $@argv
if (or (eq $e '-h') (eq $e '--help')) {
_help
return
@ -72,11 +72,11 @@ edit:add-var pdf2grey~ [@argv]{
return
}
local:params = [-colorspace gray]
var params = [-colorspace gray]
if $m[nb] {
@params = (all $params) -threshold $m[split]'%'
}
@params = $@params $m[input] $m[output]
echo 'Commande: convert '(str:join ' ' $params)
convert $@params
}
var

View File

@ -1,11 +1,11 @@
edit:add-var sendsms~ [@argv]{
use str
local:api = https://smsapi.free-mobile.fr/sendmsg
local:param = (cat $E:HOME/.config/elvish/private/freesms.json | from-json)
local:msg = (str:join '%20' $argv)
var api = https://smsapi.free-mobile.fr/sendmsg
var param = (cat $E:HOME/.config/elvish/private/freesms.json | from-json)
var msg = (str:join '%20' $argv)
local:url = $api'?user='$param[user]'&pass='$param[password]'&msg='$msg
var url = $api'?user='$param[user]'&pass='$param[password]'&msg='$msg
#put $url
curl $url
}

View File

@ -1,4 +1,4 @@
local:cmd = $e:vim~
var cmd = $e:vim~
edit:add-var vi~ [@argv]{ $cmd $@argv }
edit:add-var vb~ [@argv]{ $cmd $@argv ~/.bashrc }