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

View File

@ -1,8 +1,8 @@
edit:add-var adguard~ [@argv]{ edit:add-var adguard~ [@argv]{
use str use str
sudo chattr -i /etc/resolv.conf sudo chattr -i /etc/resolv.conf
local:beg = 's|^.*\(192\.168\.0\.25\)|' var beg = 's|^.*\(192\.168\.0\.25\)|'
local: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 end = '# '$end
} }

View File

@ -1,3 +1,5 @@
cmd = $e:arc~
edit:add-var archiver~ [@argv]{ edit:add-var archiver~ [@argv]{
use str use str
help = { help = {
@ -7,11 +9,10 @@ edit:add-var archiver~ [@argv]{
if (or (== (count $argv) 0) (eq $argv[0] -h)) { if (or (== (count $argv) 0) (eq $argv[0] -h)) {
$help $help
} }
local:format = zst var format o = zst $argv[0]
local:o = $argv[0]
if (and (str:has-prefix $o -) (> (count $o) 1)) { if (and (str:has-prefix $o -) (> (count $o) 1)) {
o = $o[1] o = $o[1]
local:m = [ var m = [
&z=zst &z=zst
&l=lz4 &l=lz4
&x=xz &x=xz
@ -21,19 +22,32 @@ edit:add-var archiver~ [@argv]{
if (not (has-key $m $o)) { if (not (has-key $m $o)) {
$help $help
} }
format = $m[$o] format argv = $m[$o] $argv[1..]
argv = $argv[1..]
} }
if (== (count $argv) 0) { if (== (count $argv) 0) {
$help $help
} }
peach [f]{ peach [f]{
local:f = $f var f = $f
if (eq $f[-1] /) { if (eq $f[-1] /) {
f = $f[..-1] f = $f[..-1]
} }
e:arc archive $f'.tar.'$format $f $cmd archive $f'.tar.'$format $f
echo "'"$f"'" archivé echo "'"$f"'" archivé
} $argv } $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 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:cset (ip:is-ip $e1) 1 0) var i1 = (condition:cset (ip:is-ip $e1) 1 0)
local:i2 = (condition:cset (ip:is-ip $e2) 1 0) var i2 = (condition:cset (ip:is-ip $e2) 1 0)
if (!= $i1 $i2) { if (!= $i1 $i2) {
< $i1 $i2 < $i1 $i2
} elif (== $i1 0) { } elif (== $i1 0) {
@ -16,9 +16,9 @@ edit:add-var cleankh~ [@argv]{
} }
} }
local:khosts = [&] var khosts = [&]
cat ~/.ssh/known_hosts | eawk [_ hosts @rest]{ cat ~/.ssh/known_hosts | eawk [_ hosts @rest]{
local:key = (str:join ' ' $rest) var key = (str:join ' ' $rest)
if (not (has-key $khosts $key)) { if (not (has-key $khosts $key)) {
khosts[$key] = [&] khosts[$key] = [&]
} }
@ -27,8 +27,8 @@ edit:add-var cleankh~ [@argv]{
} }
} }
local:lines = [(keys $khosts | each [key]{ var lines = [(keys $khosts | each [key]{
local:hosts = (keys $khosts[$key] | order &less-than=$sort-host~ | str:join ,) var hosts = (keys $khosts[$key] | order &less-than=$sort-host~ | str:join ,)
put $hosts $key | str:join ' ' put $hosts $key | str:join ' '
})] })]
echo (str:join "\n" $lines) > ~/.ssh/known_hosts echo (str:join "\n" $lines) > ~/.ssh/known_hosts

View File

@ -1,16 +1,16 @@
edit:add-var commitkcp~ [@argv]{ edit:add-var commitkcp~ [@argv]{
use str use str
local:m = [ var m = [
&name= &name=
&ver= &ver=
] ]
keys $m | each [k]{ keys $m | each [k]{
local:p = 'pkg'$k'=' var p = 'pkg'$k'='
m[$k] = (str:trim-prefix (cat PKGBUILD | grep $p | take 1) $p) 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) { if (> (count $argv) 0) {
msg = $msg' - '(str:join ' ' $argv) 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 moi/util/strutil
use str use str
local:default_records = [ var default_records = [
A A
AAAA AAAA
CNAME CNAME
@ -15,19 +15,17 @@ edit:add-var digall~ [@argv]{
NS NS
SOA SOA
] ]
local:cols = [ var cols = [
[&min=24] [&min=24]
[&min=8] [&min=8]
[&min=10] [&min=10]
] ]
local:records = [] var records servers = [] []
local:servers = [] var flags = [
local:flags = [
+noall +noall
+answer +answer
] ]
local:domains = [] var domains use_dig = [] $true
local:use_dig = $true
fn init []{ fn init []{
if (and (> (count $argv) 0) (is $argv[0] -d)) { if (and (> (count $argv) 0) (is $argv[0] -d)) {
@ -54,7 +52,7 @@ edit:add-var digall~ [@argv]{
eawk [_ @args]{ eawk [_ @args]{
put [ $args[0] (all $args[2..]) ] put [ $args[0] (all $args[2..]) ]
} $results | list:remove-duplicate | list:sort [l1 l2]{ } $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) { if (== $c 0) {
c = (str:compare $l1[2] $l2[2]) c = (str:compare $l1[2] $l2[2])
} }
@ -62,7 +60,7 @@ edit:add-var digall~ [@argv]{
} }
fn drillr [d @args]{ fn drillr [d @args]{
local:results = [ (peach [r]{ var results = [ (peach [r]{
e:drill $@args $r $d | list:filter [e]{ e:drill $@args $r $d | list:filter [e]{
and (> (count $e) 2) (not (is $e[:2] ';;')) and (> (count $e) 2) (not (is $e[:2] ';;'))
} }
@ -71,7 +69,7 @@ edit:add-var digall~ [@argv]{
} }
fn digr [d @args]{ fn digr [d @args]{
local:results = [ (peach [r]{ var results = [ (peach [r]{
e:dig $@args $r $d $@flags e:dig $@args $r $d $@flags
} $records) ] } $records) ]
format $results format $results
@ -91,7 +89,7 @@ edit:add-var digall~ [@argv]{
} }
fn digd [d]{ fn digd [d]{
local: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) @results = $@results (digs $s $d)

View File

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

View File

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

View File

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

View File

@ -1,11 +1,11 @@
edit:add-var sendsms~ [@argv]{ edit:add-var sendsms~ [@argv]{
use str use str
local:api = https://smsapi.free-mobile.fr/sendmsg var api = https://smsapi.free-mobile.fr/sendmsg
local:param = (cat $E:HOME/.config/elvish/private/freesms.json | from-json) var param = (cat $E:HOME/.config/elvish/private/freesms.json | from-json)
local:msg = (str:join '%20' $argv) 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 #put $url
curl $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 vi~ [@argv]{ $cmd $@argv }
edit:add-var vb~ [@argv]{ $cmd $@argv ~/.bashrc } edit:add-var vb~ [@argv]{ $cmd $@argv ~/.bashrc }