Tous les modules utilisés sont désormais déportés sur framagit; modification des alias en conséquence (sauf ceux concernant les pdf)

This commit is contained in:
Benjamin VAUDOUR 2021-12-27 17:54:26 +00:00
parent 8c138abe1a
commit 3c990f7cff
16 changed files with 163 additions and 191 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.old
lib/github.com
lib/framagit.org
private

View File

@ -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)'
}

View File

@ -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
}

View File

@ -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

View File

@ -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)
}
}

View File

@ -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) {
<s $e1 $e2
compare $e1 $e2
} else {
less $ip:cmp~ $e1 $e2
ip:comp $e1 $e2
}
}
@ -28,9 +28,8 @@ edit:add-var cleankh~ {|@argv|
}
var lines = [(keys $khosts | each {|key|
var hosts = (keys $khosts[$key] | order &less-than=$sort-host~ | str:join ,)
var hosts = (keys $khosts[$key] | list:sort $sort-host~ | str:join ,)
put $hosts $key | str:join ' '
})]
echo (str:join "\n" $lines) > ~/.ssh/known_hosts
}

View File

@ -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
}

View File

@ -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

View File

@ -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])
}

View File

@ -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
}
}

View File

@ -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) {
<s $e1 $e2
var check = {|e| common:cexec (ip:is-ipv4 $e) 0 { common:cond (ip:is-ipv6 $e) 1 2 }}
var i1 = ($check $e1)
var i2 = ($check $e2)
if (or (!= $i1 $i2) (== $i1 2)) {
compare $i1 $i2
} elif (== $i1 1) {
less $ip:cmp6~ $e1 $e2
ip:comp6 $e1 $e2
} else {
less $ip:cmp4~ $e1 $e2
ip:comp4 $e1 $e2
}
}
@ -27,8 +26,8 @@ edit:add-var ipof~ {|@argv|
]
e:dnscrypt-proxy -config /etc/dnscrypt-proxy/dnscrypt-proxy.toml -resolve (idn -a $d) | peach {|l|
var ll = $l
var idx = (+ (str:index $ll :) 1)
var value = (str:trim-space $ll[$idx".."])
var idx = (num:++ (str:index $ll :))
var value = (str:trim-space $ll[$idx..])
if (or (str:has-prefix $ll 'IPv4 addresses') (str:has-prefix $ll 'IPv6 addresses')) {
str:split ', ' $value | peach {|e|
var ee = $e
@ -68,20 +67,19 @@ edit:add-var ipof~ {|@argv|
peach {|d|
var dd = $d
var solve = (dnssolve $dd)
if (> (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)

View File

@ -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
}

View File

@ -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

View File

@ -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)] [<chars>] [<size>]'
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 '<chars> Liste de caractères possibles'
echo '<size> Longueur de la chaîne (par défaut: 10)'
echo ''
echo 'Si aucune classe de caractères ou liste de caractères nest 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)] [<chars>] [<size>]'
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 '<chars> Liste de caractères possibles'
echo '<size> Longueur de la chaîne (par défaut: 10)'
echo ''
echo 'Si aucune classe de caractères ou liste de caractères nest 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
}
}

View File

@ -1,3 +1,3 @@
edit:add-var riot~ {||
edit:add-var riot~ {
cat $E:HOME/.config/elvish/private/riot.txt | xclip -selection clipboard
}

View File

@ -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
}