From 3c990f7cff3cca328fd8d16a4824d5b7c2a21a82 Mon Sep 17 00:00:00 2001 From: Benjamin VAUDOUR Date: Mon, 27 Dec 2021 17:54:26 +0000 Subject: [PATCH] =?UTF-8?q?Tous=20les=20modules=20utilis=C3=A9s=20sont=20d?= =?UTF-8?q?=C3=A9sormais=20d=C3=A9port=C3=A9s=20sur=20framagit;=20modifica?= =?UTF-8?q?tion=20des=20alias=20en=20cons=C3=A9quence=20(sauf=20ceux=20con?= =?UTF-8?q?cernant=20les=20pdf)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + aliases/addbadips.elv | 47 +++++++++++------- aliases/arc.elv | 9 ++-- aliases/carapace.elv | 3 +- aliases/checklinks.elv | 3 +- aliases/cleankh.elv | 21 ++++---- aliases/commitkcp.elv | 10 ++-- aliases/digall.elv | 70 ++++++++++++-------------- aliases/get-uid.elv | 12 ++--- aliases/ipinfo.elv | 7 ++- aliases/ipof.elv | 44 ++++++++--------- aliases/meteo.elv | 5 +- aliases/publicip.elv | 7 +-- aliases/random.elv | 109 ++++++++++++++++------------------------- aliases/riot.elv | 2 +- aliases/sendsms.elv | 4 +- 16 files changed, 163 insertions(+), 191 deletions(-) diff --git a/.gitignore b/.gitignore index 25f1436..f40a3a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.old lib/github.com +lib/framagit.org private diff --git a/aliases/addbadips.elv b/aliases/addbadips.elv index 8d969de..4e73fe0 100644 --- a/aliases/addbadips.elv +++ b/aliases/addbadips.elv @@ -1,25 +1,34 @@ edit:add-var addbadips~ {|@argv| - use moi/util/ip - use moi/util/list - use moi/util/map use str + use framagit.org/benjamin.vaudour/elv-lib/mods/ip + use framagit.org/benjamin.vaudour/elv-lib/mods/list + use framagit.org/benjamin.vaudour/elv-lib/mods/map - var f = ~/bad_ips.txt - var ips = [ (cat $f) ] - var m c = (map:to-set $ips) 0 - each {|e| - var cond = (and (not (has-key $m $e)) (ip:is-ipv4 $e)) - if $cond { - echo $e ajoutée - set c = (+ $c 1) - set m[$e] = $nil - set ips = [ (all $ips) $e ] + fn add {|f cmp ips| + var @cips = (cat $f) + var m c = (map:to-set $cips) 0 + each {|e| + if (not (has-key $m $e)) { + echo $e ajoutée + set c = (+ $c 1) + set m[$e] = $nil + set @cips = $@cips $e + } + } $ips + if (> $c 0) { + set @cips = (list:sort $cmp $cips) + echo (str:join "\n" $cips) > $f } - } $argv - if (> $c 0) { - set ips = [ (list:sort $ip:cmp4~ $ips) ] + put $c (count $cips) + } + + var ip4 ip6 = (list:filter $ip:is-ip~ $argv | list:unzip {|_ ip| ip:is-ipv4 $ip}) + if (list:is-not-empty $ip4) { + var c t = (add $E:HOME/bad_ips.txt $ip:comp4~ $ip4) + printf "%d IPv4s ajoutées (%d au total)\n" $c $t + } + if (list:is-not-empty $ip6) { + var c t = (add $E:HOME/bad_ipsv6.txt $ip:comp6~ $ip6) + printf "%d IPv6s ajoutées (%d au total)\n" $c $t } - var result = (str:join "\n" $ips) - echo $result > $f - echo $c' IPs ajoutées ('(count $ips)' au total)' } diff --git a/aliases/arc.elv b/aliases/arc.elv index 9e51066..6502807 100644 --- a/aliases/arc.elv +++ b/aliases/arc.elv @@ -28,12 +28,9 @@ edit:add-var archiver~ {|@argv| $help } peach {|f| - var ff = $f - if (eq $ff[-1] /) { - set f = $ff[..-1] - } + var ff = (str:trim-suffix $f '/') $cmd archive $ff'.tar.'$format $ff - echo "'"$ff"'" archivé + printf "'%s' archivé\n" $ff } $argv } @@ -41,7 +38,7 @@ edit:add-var desarchiver~ {|@argv| peach {|f| var ff = $f $cmd unarchive $ff - echo "'"$ff"'" désarchivé + printf "'%s' désarchivé\n" $ff } $argv } diff --git a/aliases/carapace.elv b/aliases/carapace.elv index 4ccc987..7cd7b3e 100644 --- a/aliases/carapace.elv +++ b/aliases/carapace.elv @@ -1,4 +1,5 @@ edit:add-var updatecarapace~ {|| + use path var cur = (pwd) var wd = $E:HOME/Documents/OtherGo/github.com/rsteube/carapace-bin var bd = $E:HOME/Go/bin @@ -7,7 +8,7 @@ edit:add-var updatecarapace~ {|| cd cmd/carapace go generate ./... go build -ldflags="-s -w" -tags release - if (bool ?(test -f carapace)) { + if (path:is-regular carapace) { mv -f carapace $bd } cd $cur diff --git a/aliases/checklinks.elv b/aliases/checklinks.elv index 13b9367..4d966da 100644 --- a/aliases/checklinks.elv +++ b/aliases/checklinks.elv @@ -1,13 +1,14 @@ use str fn -check {|f| + use str var @missings = (try { sudo ldd $f 2>/dev/null | grep 'not found' | eawk {|_ m @_| put $m } } except e { }) if (> (count $missings) 1) { var p = (LC_ALL=C pacman -Qo $f) - echo $p' seem broken: missing '(str:join ', ' $missings) + printf "%s seem broken: missing %s\n" $p (str:join ', ' $missings) } } diff --git a/aliases/cleankh.elv b/aliases/cleankh.elv index 50c83cd..e32dc0b 100644 --- a/aliases/cleankh.elv +++ b/aliases/cleankh.elv @@ -1,18 +1,18 @@ edit:add-var cleankh~ {|@argv| use str - use moi/util/condition - use moi/util/list - use moi/util/ip - fn less {|cmp e1 e2| < ($cmp $e1 $e2) 0 } + use framagit.org/benjamin.vaudour/elv-lib/mods/common + use framagit.org/benjamin.vaudour/elv-lib/mods/ip + use framagit.org/benjamin.vaudour/elv-lib/mods/list + fn sort-host {|e1 e2| - var i1 = (condition:cset (ip:is-ip $e1) 1 0) - var i2 = (condition:cset (ip:is-ip $e2) 1 0) + var i1 = (common:cond (ip:is-ip $e1) 1 0) + var i2 = (common:cond (ip:is-ip $e2) 1 0) if (!= $i1 $i2) { - < $i1 $i2 + - $i1 $i2 } elif (== $i1 0) { - ~/.ssh/known_hosts } - diff --git a/aliases/commitkcp.elv b/aliases/commitkcp.elv index 634dd8d..d8272b0 100644 --- a/aliases/commitkcp.elv +++ b/aliases/commitkcp.elv @@ -1,20 +1,20 @@ edit:add-var commitkcp~ {|@argv| use str + var m = [ &name= &ver= ] - keys $m | each {|k| - var p = 'pkg'$k'=' + var p = (printf 'pkg%s=' $k) set m[$k] = (str:trim-prefix (cat PKGBUILD | grep $p | take 1) $p) } - var msg = $m[name]' '$m[ver] + var msg = (printf '%s %s' $m[name] $m[ver]) if (> (count $argv) 0) { - set msg = $msg' - '(str:join ' ' $argv) + set msg = (printf '%s - %s' $msg (str:join ' ' $argv)) } - echo "git commit -am '"$msg"' ; git push" + printf "git commit -am '%s'; git push" $msg git commit -am $msg; git push } diff --git a/aliases/digall.elv b/aliases/digall.elv index 15aef3b..793e9a5 100644 --- a/aliases/digall.elv +++ b/aliases/digall.elv @@ -1,7 +1,8 @@ edit:add-var digall~ {|@argv| - use moi/util/list - use moi/util/strutil use str + use framagit.org/benjamin.vaudour/elv-lib/mods/common + use framagit.org/benjamin.vaudour/elv-lib/mods/format + use framagit.org/benjamin.vaudour/elv-lib/mods/list var default_records = [ A @@ -15,82 +16,73 @@ edit:add-var digall~ {|@argv| NS SOA ] - var cols = [ - [&min=24] - [&min=8] - [&min=10] - ] var records servers = [] [] var flags = [ +noall +answer ] var domains use_dig = [] $true - - fn init {|| - if (and (> (count $argv) 0) (is $argv[0] -d)) { - set use_dig = $false - set argv = $argv[1:] + + fn init { + if (and (list:is-not-empty $argv) (eq $argv[0] -d)) { + set use_dig argv = $false $argv[1..] } each {|e| - if (is $e[0] '+') { - set flags = [ (all $flags) $e ] - } elif (is $e[0] @) { - set servers = [ (all $servers) $e ] - } elif (list:includes $e $default_records) { - set records = [ (all $records) $e ] + if (eq $e[0] +) { + set @flags = $@flags $e + } elif (eq $e[0] @) { + set @servers = $@servers $e + } elif (list:contains $e $default_records) { + set @records = $@records $e } else { - set domains = [ (all $domains) $e ] + set @domains = $@domains $e } } $argv - if (== (count $records) 0) { + if (list:is-empty $records) { set records = $default_records } } - + fn format {|results| eawk {|_ @args| put [ $args[0] (all $args[2..]) ] } $results | list:remove-duplicate | list:sort {|l1 l2| - var c = (str:compare $l1[0] $l2[0]) + var c = (compare $l1[0] $l2[0]) if (== $c 0) { - set c = (str:compare $l1[2] $l2[2]) + set c = (compare $l1[2] $l2[2]) } - } | strutil:format &col=$cols | str:join "\n" + put $c + } | each {|e| str:join ' ' $e} | format:tabulate } - + fn drillr {|d @args| - var results = [ (peach {|r| + var @results = (peach {|r| e:drill $@args $r $d | list:filter {|e| - and (> (count $e) 2) (not (is $e[:2] ';;')) + and (> (count $e) 2) (not-eq $e[..2] ';;') } - } $records) ] + } $records) format $results } fn digr {|d @args| - var results = [ (peach {|r| + var @results = (peach {|r| e:dig $@args $r $d $@flags - } $records) ] + } $records) format $results } - + fn req {|d @args| - if $use_dig { - digr $d $@args - } else { - drillr $d $@args - } + common:cexec $use_dig { digr $d $@args } { drillr $d $@args } } - + fn digs {|s d| put (echo (styled $s bright-yellow)) req $d $s } fn digd {|d| - var results = [ (echo (styled 'Domaine: '$d bright-green)) ] - if (> (count $servers) 0) { + var @results = (echo (styled 'Domaine: '$d bright-green)) + if (list:is-not-empty $servers) { each {|s| set @results = $@results (digs $s $d) } $servers diff --git a/aliases/get-uid.elv b/aliases/get-uid.elv index 7a963b9..332f8f1 100644 --- a/aliases/get-uid.elv +++ b/aliases/get-uid.elv @@ -1,7 +1,5 @@ -use re -use str - fn -value {|v| + use re var p = (re:find '^(\d+)\((\w+)\)$' $v) if (and (has-key $p groups) (== (count $p[groups]) 3)) { put [ @@ -12,7 +10,8 @@ fn -value {|v| } fn -values {|v| - var vv = [ (str:split ',' $v) ] + use str + var @vv = (str:split ',' $v) if (== (count $vv) 1) { -value $vv[0] } else { @@ -20,10 +19,11 @@ fn -values {|v| } } -fn -get-id {|| +fn -get-id { + use str var id = [&] str:split ' ' (id) | each {|e| - var p = [ (str:split '=' $e) ] + var @p = (str:split '=' $e) if (== (count $p) 2) { set id[$p[0]] = (-values $p[1]) } diff --git a/aliases/ipinfo.elv b/aliases/ipinfo.elv index d12e355..acd386e 100644 --- a/aliases/ipinfo.elv +++ b/aliases/ipinfo.elv @@ -1,17 +1,16 @@ edit:add-var ipinfo~ {|@argv| - use moi/util/ip - use str + use framagit.org/benjamin.vaudour/elv-lib/mods/ip var token = (cat $E:HOME/.config/elvish/private/ipinfo_token) fn url-of {|ip| - str:join '' [ 'ipinfo.io/' $ip '?token=' $token] + printf 'ipinfo.io/%s?token=%s' $ip $token } fn info {|ip| if (ip:is-ip $ip) { var url = (url-of $ip) - echo 'URL: '$url + printf "URL: %s\n" $url e:curlie $url } } diff --git a/aliases/ipof.elv b/aliases/ipof.elv index 9f966e9..9b7c59f 100644 --- a/aliases/ipof.elv +++ b/aliases/ipof.elv @@ -1,21 +1,20 @@ edit:add-var ipof~ {|@argv| use str - use moi/util/condition - use moi/util/ip - - fn less {|cmp e1 e2| < ($cmp $e1 $e2) 0 } + use framagit.org/benjamin.vaudour/elv-lib/mods/common + use framagit.org/benjamin.vaudour/elv-lib/mods/ip + use framagit.org/benjamin.vaudour/elv-lib/mods/list + use framagit.org/benjamin.vaudour/elv-lib/mods/num fn sort-ip {|e1 e2| - 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) { - (keys $solve[ips] | count) 0) { + if (> (count $solve[ips]) 0) { set remote[$dd] = $solve } } $argv each {|d| var exists = $false - echo (styled 'Resolving '$d'…' bright-green) - echo + echo (styled (printf "Resolving '%s'…\n" $d) bright-green) if (has-key $hosts $d) { set exists = $true echo (styled ' local:' bright-yellow) - keys $hosts[$d] | order &less-than=$sort-ip~ | each {|ip| - echo ' - '$ip + keys $hosts[$d] | list:sort $sort-ip~ | each {|ip| + printf " - %s\n" $ip } } if (and (has-key $remote $d) $remote[$d][remote]) { @@ -89,11 +87,11 @@ edit:add-var ipof~ {|@argv| var info = $remote[$d] echo (styled ' remote:' bright-yellow) echo ' IPs:' - keys $info[ips] | order &less-than=$sort-ip~ | each {|ip| - echo ' - '$ip + keys $info[ips] | list:sort $sort-ip~ | each {|ip| + printf " - %s\n" $ip } - echo ' Resolvers: '$info[resolvers] - echo ' TXT records: '$info[txt] + printf " Resolvers: %s\n" $info[resolvers] + printf " TXT records: %s\n" $info[txt] } if (not $exists) { echo (styled 'No info found' bright-red) diff --git a/aliases/meteo.elv b/aliases/meteo.elv index d80e9bf..2b6b8e5 100644 --- a/aliases/meteo.elv +++ b/aliases/meteo.elv @@ -1,5 +1,6 @@ edit:add-var meteo~ {|@argv| use str - #curl --connect-timeout 2 "wttr.in/"(joins '' $_args)"?lang=fr" - e:curlie -s --connect-timeout 2 "wttr.in/"(str:join '' $argv)"?lang=fr" + var url = (printf 'wttr.in/%s?lang=fr' (str:join '' $argv)) + #curl --connect-timeout 2 $url + e:curlie -s --connect-timeout 2 $url } diff --git a/aliases/publicip.elv b/aliases/publicip.elv index a37ee36..4786ffa 100644 --- a/aliases/publicip.elv +++ b/aliases/publicip.elv @@ -1,9 +1,10 @@ edit:add-var publicip~ {|@argv| + use framagit.org/benjamin.vaudour/elv-lib/mods/common var f = {|t| use moi/util/condition - set t = (condition:cset (eq $t -6) -6 -4) - 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 } + set t = (common:cond (eq $t -6) -6 -4) + var l = (common:cond (eq $t -6) 'IPv6: ' 'IPv4: ') + e:curl $t ifconfig.co/ip 2> /dev/null | each {|ip| echo (styled $l bold yellow) $ip} } $f -4 $f -6 diff --git a/aliases/random.elv b/aliases/random.elv index 1ac3063..cd52252 100644 --- a/aliases/random.elv +++ b/aliases/random.elv @@ -1,94 +1,67 @@ -use str -use re +edit:add-var genstr~ {|@argv| + use re + use str -fn -bytes {|begin size| - str:from-codepoints (range $begin (+ $begin $size)) -} + fn j {|@strings| str:join '' $strings} + fn bytes {|begin size| str:from-codepoints (range $begin (+ $begin $size))} + fn upper { bytes 0x41 26 } + fn lower { bytes 0x61 26 } + fn digit { bytes 0x30 10 } + fn alpha { j (upper) (lower) } + fn alphanum { j (alpha) (digit) } -fn -upper {|| - -bytes 0x41 26 -} + fn random {|chars| + var size = (count $chars) + print $chars[(randint 0 $size)] + } + fn is-int {|arg| re:match '^\d+$' $arg} -fn -lower {|| - -bytes 0x61 26 -} + fn help {|| + echo 'Génère une chaîne de caractères aléatoires' + echo 'Usage: genstr [(-auldh)] [] []' + echo '' + echo 'Options:' + echo ' -a Uniquement des lettres ([A-Za-z])' + echo ' -u Uniquement des lettres majuscules ([A-Z])' + echo ' -l Uniquement des lettres minuscules ([a-z])' + echo ' -d Uniquement des chiffres ([0-9])' + echo '' + echo ' Liste de caractères possibles' + echo ' Longueur de la chaîne (par défaut: 10)' + echo '' + echo 'Si aucune classe de caractères ou liste de caractères n’est fournie, utilise les caractères alphanumériques ([A-Za-z0-9]).' + } -fn -digit {|| - -bytes 0x30 10 -} - -fn -j {|@strings| - str:join '' $strings -} - -fn -alpha {|| - -j (-upper) (-lower) -} - -fn -alphanum {|| - -j (-alpha) (-digit) -} - -fn -random {|chars| - var size = (count $chars) - print $chars[(randint 0 $size)] -} - -fn -is-int {|arg| - re:match '^\d+$' $arg -} - -fn -help {|| - echo 'Génère une chaîne de caractères aléatoires' - echo 'Usage: genstr [(-auldh)] [] []' - echo '' - echo 'Options:' - echo ' -a Uniquement des lettres ([A-Za-z])' - echo ' -u Uniquement des lettres majuscules ([A-Z])' - echo ' -l Uniquement des lettres minuscules ([a-z])' - echo ' -d Uniquement des chiffres ([0-9])' - echo '' - echo ' Liste de caractères possibles' - echo ' Longueur de la chaîne (par défaut: 10)' - echo '' - echo 'Si aucune classe de caractères ou liste de caractères n’est fournie, utilise les caractères alphanumériques ([A-Za-z0-9]).' -} - -edit:add-var genstr~ {|@args| var len chars h = 0 '' $false each {|e| if (or (eq $e -h) (eq $e --help)) { set h = $true - -help + help break } elif (eq $e -a) { - set chars = (-j $chars (-alpha)) + set chars = (j $chars (alpha)) } elif (eq $e -u) { - set chars = (-j $chars (-upper)) + set chars = (j $chars (upper)) } elif (eq $e -l) { - set chars = (-j $chars (-lower)) + set chars = (j $chars (lower)) } elif (eq $e -d) { - set chars = (-j $chars (-digit)) - } elif (and (-is-int $e) (> $e 0)) { + set chars = (j $chars (digit)) + } elif (and (is-int $e) (> $e 0)) { set len = $e } else { - set chars = (-j $chars $e) + set chars = (j $chars $e) } - } $args + } $argv if (not $h) { if (== $len 0) { set len = 10 } if (eq $chars '') { - set chars = (-alphanum) - } - - set chars = [(str:split '' $chars)] - - range $len | each {|_| - -random $chars + set chars = (alphanum) } + set @chars = (str:split '' $chars) + range $len | each {|_| random $chars} echo } } diff --git a/aliases/riot.elv b/aliases/riot.elv index ab1e83e..8925b2d 100644 --- a/aliases/riot.elv +++ b/aliases/riot.elv @@ -1,3 +1,3 @@ -edit:add-var riot~ {|| +edit:add-var riot~ { cat $E:HOME/.config/elvish/private/riot.txt | xclip -selection clipboard } diff --git a/aliases/sendsms.elv b/aliases/sendsms.elv index 6e1ba23..373aaef 100644 --- a/aliases/sendsms.elv +++ b/aliases/sendsms.elv @@ -5,7 +5,7 @@ edit:add-var sendsms~ {|@argv| var param = (cat $E:HOME/.config/elvish/private/freesms.json | from-json) var msg = (str:join '%20' $argv) - var url = $api'?user='$param[user]'&pass='$param[password]'&msg='$msg + var url = (printf '%s?user=%s&pass=%s&msg=%s' $api $param[user] $param[password] $msg) #put $url - curl $url + e:curl $url }