From b3d74ce2d7e7c9a032cfdea2fabba6282d47f518 Mon Sep 17 00:00:00 2001 From: Benjamin VAUDOUR Date: Sun, 16 Jun 2024 12:18:51 +0200 Subject: [PATCH] Refonte des aliases --- aliases/addbadips.elv | 33 --------- aliases/aliases.elv | 5 +- aliases/{checklinks.elv => check-links.elv} | 2 +- .../{cleankh.elv => clean-known-hosts.elv} | 2 +- aliases/{commitkcp.elv => commit-kcp.elv} | 2 +- aliases/{digall.elv => dig.elv} | 2 +- aliases/grawlix.elv | 17 ----- aliases/ipinfo.elv | 18 ----- aliases/{ipof.elv => ips.elv} | 67 ++++++++++++++++++- aliases/meteo.elv | 6 +- aliases/pacman.elv | 7 ++ aliases/pacmanhisto.elv | 1 - aliases/publicip.elv | 9 --- aliases/random.elv | 20 +++++- aliases/{sendsms.elv => send-sms.elv} | 2 +- aliases/transfer.elv | 21 ------ aliases/translate.elv | 2 - aliases/upd.elv | 6 -- aliases/vi.elv | 2 +- aliases/{vivaldiprofile.elv => vivaldi.elv} | 0 aliases/which.elv | 28 ++++++++ rc.elv | 10 +-- 22 files changed, 138 insertions(+), 124 deletions(-) delete mode 100644 aliases/addbadips.elv rename aliases/{checklinks.elv => check-links.elv} (96%) rename aliases/{cleankh.elv => clean-known-hosts.elv} (97%) rename aliases/{commitkcp.elv => commit-kcp.elv} (92%) rename aliases/{digall.elv => dig.elv} (98%) delete mode 100644 aliases/grawlix.elv delete mode 100644 aliases/ipinfo.elv rename aliases/{ipof.elv => ips.elv} (63%) create mode 100644 aliases/pacman.elv delete mode 100644 aliases/pacmanhisto.elv delete mode 100644 aliases/publicip.elv rename aliases/{sendsms.elv => send-sms.elv} (90%) delete mode 100644 aliases/transfer.elv delete mode 100644 aliases/translate.elv delete mode 100644 aliases/upd.elv rename aliases/{vivaldiprofile.elv => vivaldi.elv} (100%) create mode 100644 aliases/which.elv diff --git a/aliases/addbadips.elv b/aliases/addbadips.elv deleted file mode 100644 index 3b63b11..0000000 --- a/aliases/addbadips.elv +++ /dev/null @@ -1,33 +0,0 @@ -edit:add-var addbadips~ {|@argv| - 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 - - fn add {|f cmp ips t| - var @cips = (cat $f) - var m c = (map:to-set $cips) 0 - each {|e| - if (not (has-key $m $e)) { - set m[$e] = $nil - set @cips = $@cips $e - set c = (+ $c 1) - echo $e ajoutée - } - } $ips - if (> $c 0) { - set @cips = (list:sort $cmp $cips) - echo (str:join "\n" $cips) > $f - } - printf "%d %s ajoutées (%d au total)\n" $c $t (count $cips) - } - - - var ip4 ip6 = (list:filter $ip:is-ip~ $argv | list:unzip {|_ ip| ip:is-ipv4 $ip}) - if (list:is-not-empty $ip4) { - add $E:HOME/ips/bad_ips.txt $ip:comp4~ $ip4 IPv4s - } - if (list:is-not-empty $ip6) { - add $E:HOME/ips/bad_ipsv6.txt $ip:comp6~ $ip6 IPv6s - } -} diff --git a/aliases/aliases.elv b/aliases/aliases.elv index 2893e71..67264f0 100644 --- a/aliases/aliases.elv +++ b/aliases/aliases.elv @@ -3,20 +3,19 @@ edit:add-var cat~ {|@argv| e:bat -pp --tabs 2 $@argv } edit:add-var cp~ {|@argv| e:cp -iv $@argv } edit:add-var curl~ $e:curlie~ edit:add-var df~ $e:duf~ -edit:add-var diff~ $e:colordiff~ +edit:add-var diff~ $e:delta~ edit:add-var dig~ {|@argv| e:dig +noall +answer $@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 } fn -erd {|@argv| e:erd -HlI --dir-order last --sort name --layout inverted $@argv } #edit:add-var erd~ $-erd~ -#edit:add-var git~ $e:hub~ edit:add-var grep~ {|@argv| e:grep --color=tty -d skip $@argv } #edit:add-var grep~ {|@argv| e:ack $@argv } edit:add-var hx~ {|@argv| e:helix $@argv } edit:add-var mv~ {|@argv| e:mv -iv $@argv } edit:add-var pf~ {|@argv| e:pkgfile -vri $@argv } edit:add-var rm~ {|@argv| e:rm -Iv $@argv } -edit:add-var rename~ $e:go-rename~ +edit:add-var rename~ {|@argv| /home/benjamin/bin/rename $@argv } edit:add-var sudo~ {|@argv| fail 'Use doas instead'} edit:add-var timidity~ {|@argv| e:timidity -a -K -1 $@argv } edit:add-var trdsql~ {|@argv| e:trdsql -ih -id ';' -omd $@argv } diff --git a/aliases/checklinks.elv b/aliases/check-links.elv similarity index 96% rename from aliases/checklinks.elv rename to aliases/check-links.elv index 3dc5814..b09212f 100644 --- a/aliases/checklinks.elv +++ b/aliases/check-links.elv @@ -34,7 +34,7 @@ fn -copt {|| doas find /opt -maxdepth 3 -type f 2>/dev/null | each $-check-executable~ } -edit:add-var checklinks~ {|| +edit:add-var check-links~ {|| -cbin -clib -copt diff --git a/aliases/cleankh.elv b/aliases/clean-known-hosts.elv similarity index 97% rename from aliases/cleankh.elv rename to aliases/clean-known-hosts.elv index 4babaf1..c7bd2e3 100644 --- a/aliases/cleankh.elv +++ b/aliases/clean-known-hosts.elv @@ -1,4 +1,4 @@ -edit:add-var cleankh~ {|@argv| +edit:add-var clean-known-hosts~ {|@argv| use re use str use framagit.org/benjamin.vaudour/elv-lib/mods/common diff --git a/aliases/commitkcp.elv b/aliases/commit-kcp.elv similarity index 92% rename from aliases/commitkcp.elv rename to aliases/commit-kcp.elv index f9e0813..64fe6c1 100644 --- a/aliases/commitkcp.elv +++ b/aliases/commit-kcp.elv @@ -1,4 +1,4 @@ -edit:add-var commitkcp~ {|@argv| +edit:add-var commit-kcp~ {|@argv| use str var m = [ diff --git a/aliases/digall.elv b/aliases/dig.elv similarity index 98% rename from aliases/digall.elv rename to aliases/dig.elv index 28b5c9d..644cea4 100644 --- a/aliases/digall.elv +++ b/aliases/dig.elv @@ -1,4 +1,4 @@ -edit:add-var digall~ {|@argv| +edit:add-var dig-all~ {|@argv| use re use str use framagit.org/benjamin.vaudour/elv-lib/mods/common diff --git a/aliases/grawlix.elv b/aliases/grawlix.elv deleted file mode 100644 index 443bdf2..0000000 --- a/aliases/grawlix.elv +++ /dev/null @@ -1,17 +0,0 @@ -use str - -edit:add-var grawlix~ {|@argv| - var @chars = (str:split '' '#$%&*+=^~£§¶±÷≠Ω√∆◊') - var nbChars = (count $chars) - var length = (shuf -i 4-7 -n 1) - var graw = [] - - range $length | each {|_| - var ci = (shuf -i 1-$nbChars -n 1) - set @graw = $@graw $chars[(- $ci 1)] - } - - set @graw = $@graw '!' - - echo (str:join '' $graw) -} diff --git a/aliases/ipinfo.elv b/aliases/ipinfo.elv deleted file mode 100644 index acd386e..0000000 --- a/aliases/ipinfo.elv +++ /dev/null @@ -1,18 +0,0 @@ -edit:add-var ipinfo~ {|@argv| - use framagit.org/benjamin.vaudour/elv-lib/mods/ip - - var token = (cat $E:HOME/.config/elvish/private/ipinfo_token) - - fn url-of {|ip| - printf 'ipinfo.io/%s?token=%s' $ip $token - } - - fn info {|ip| - if (ip:is-ip $ip) { - var url = (url-of $ip) - printf "URL: %s\n" $url - e:curlie $url - } - } - each $info~ $argv -} diff --git a/aliases/ipof.elv b/aliases/ips.elv similarity index 63% rename from aliases/ipof.elv rename to aliases/ips.elv index 0c5df01..0af7e0c 100644 --- a/aliases/ipof.elv +++ b/aliases/ips.elv @@ -1,4 +1,58 @@ -edit:add-var ipof~ {|@argv| +edit:add-var add-badips~ {|@argv| + 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 + + fn add {|f cmp ips t| + var @cips = (cat $f) + var m c = (map:to-set $cips) 0 + each {|e| + if (not (has-key $m $e)) { + set m[$e] = $nil + set @cips = $@cips $e + set c = (+ $c 1) + echo $e ajoutée + } + } $ips + if (> $c 0) { + set @cips = (list:sort $cmp $cips) + echo (str:join "\n" $cips) > $f + } + printf "%d %s ajoutées (%d au total)\n" $c $t (count $cips) + } + + + var ip4 ip6 = (list:filter $ip:is-ip~ $argv | list:unzip {|_ ip| ip:is-ipv4 $ip}) + if (list:is-not-empty $ip4) { + add $E:HOME/ips/bad_ips.txt $ip:comp4~ $ip4 IPv4s + } + if (list:is-not-empty $ip6) { + add $E:HOME/ips/bad_ipsv6.txt $ip:comp6~ $ip6 IPv6s + } +} + +edit:add-var ip-info~ {|@argv| + use framagit.org/benjamin.vaudour/elv-lib/mods/ip + + var token = (cat $E:HOME/.config/elvish/private/ipinfo_token) + + fn url-of {|ip| + printf 'ipinfo.io/%s?token=%s' $ip $token + } + + fn info {|ip| + if (ip:is-ip $ip) { + var url = (url-of $ip) + printf "URL: %s\n" $url + e:curlie $url + } + } + + each $info~ $argv +} + +edit:add-var ip-of~ {|@argv| use re use str use framagit.org/benjamin.vaudour/elv-lib/mods/common @@ -100,3 +154,14 @@ edit:add-var ipof~ {|@argv| echo } $argv } + +edit:add-var ip-public~ {|@argv| + use framagit.org/benjamin.vaudour/elv-lib/mods/common + var f = {|t| + 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/meteo.elv b/aliases/meteo.elv index 2b6b8e5..1dd4860 100644 --- a/aliases/meteo.elv +++ b/aliases/meteo.elv @@ -1,6 +1,10 @@ edit:add-var meteo~ {|@argv| use str - var url = (printf 'wttr.in/%s?lang=fr' (str:join '' $argv)) + var city = 'Montbéliard' + if (> (count $argv) 0) { + set city = (str:join '' $argv) + } + var url = (printf 'wttr.in/%s?lang=fr' $city) #curl --connect-timeout 2 $url e:curlie -s --connect-timeout 2 $url } diff --git a/aliases/pacman.elv b/aliases/pacman.elv new file mode 100644 index 0000000..157a407 --- /dev/null +++ b/aliases/pacman.elv @@ -0,0 +1,7 @@ +edit:add-var pacman-histo~ {|@argv| e:cat /var/log/pacman.log | e:rg "ALPM" | e:rg $@argv } + +edit:add-var upd~ {|@args| + if ?(mirror-check --fast) { + doas pacman -Syu + } +} diff --git a/aliases/pacmanhisto.elv b/aliases/pacmanhisto.elv deleted file mode 100644 index 252bfdd..0000000 --- a/aliases/pacmanhisto.elv +++ /dev/null @@ -1 +0,0 @@ -edit:add-var pacmanhisto~ {|@argv| e:cat /var/log/pacman.log | e:rg "ALPM" | e:rg $@argv } diff --git a/aliases/publicip.elv b/aliases/publicip.elv deleted file mode 100644 index b76f17b..0000000 --- a/aliases/publicip.elv +++ /dev/null @@ -1,9 +0,0 @@ -edit:add-var publicip~ {|@argv| - use framagit.org/benjamin.vaudour/elv-lib/mods/common - var f = {|t| - 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 cd52252..f4660f6 100644 --- a/aliases/random.elv +++ b/aliases/random.elv @@ -1,4 +1,4 @@ -edit:add-var genstr~ {|@argv| +edit:add-var gen-str~ {|@argv| use re use str @@ -65,3 +65,21 @@ edit:add-var genstr~ {|@argv| echo } } + +edit:add-var grawlix~ {|@argv| + use str + + var @chars = (str:split '' '#$%&*+=^~£§¶±÷≠Ω√∆◊') + var nbChars = (count $chars) + var length = (shuf -i 4-7 -n 1) + var graw = [] + + range $length | each {|_| + var ci = (shuf -i 1-$nbChars -n 1) + set @graw = $@graw $chars[(- $ci 1)] + } + + set @graw = $@graw '!' + + echo (str:join '' $graw) +} diff --git a/aliases/sendsms.elv b/aliases/send-sms.elv similarity index 90% rename from aliases/sendsms.elv rename to aliases/send-sms.elv index 373aaef..727b2fa 100644 --- a/aliases/sendsms.elv +++ b/aliases/send-sms.elv @@ -1,4 +1,4 @@ -edit:add-var sendsms~ {|@argv| +edit:add-var send-sms~ {|@argv| use str var api = https://smsapi.free-mobile.fr/sendmsg diff --git a/aliases/transfer.elv b/aliases/transfer.elv deleted file mode 100644 index 607a5c3..0000000 --- a/aliases/transfer.elv +++ /dev/null @@ -1,21 +0,0 @@ -var domain = https://transfer.hostux.net/ -edit:add-var transfer~ {|@argv| - use path - if (not-eq (count $argv) 0) { - fail('Usage: transfer ') - } - var file = $argv[0] - var filename = (basename $file) - var is_dir = (path:is-dir &follow-symlink=$true $file) - var is_regular = (path:is-regular &follow-symlink=$true $file) - if (not (and is_dir is_regular)) { - fail("'"$file"' n’existe pas") - } - if is_dir { - set filename = $filename'.tar.gz' - cd $file - tar -c . | e:curl --progress-bar --upload-file - $domain$filename | tee /dev/null - } else { - cat $file | e:curl --progress-bar --upload-file - $domain$filename | teee /dev/null - } -} diff --git a/aliases/translate.elv b/aliases/translate.elv deleted file mode 100644 index b64214d..0000000 --- a/aliases/translate.elv +++ /dev/null @@ -1,2 +0,0 @@ -edit:add-var trsen~ {|@argv| e:rlwrap trans -b -t en $@argv } -edit:add-var trsfr~ {|@argv| e:rlwrap trans -b -t fr $@argv } diff --git a/aliases/upd.elv b/aliases/upd.elv deleted file mode 100644 index b69d7a3..0000000 --- a/aliases/upd.elv +++ /dev/null @@ -1,6 +0,0 @@ -edit:add-var upd~ {|@args| - if ?(mirror-check --fast) { - doas pacman -Syu - } -} - diff --git a/aliases/vi.elv b/aliases/vi.elv index 7764bfe..ec264e1 100644 --- a/aliases/vi.elv +++ b/aliases/vi.elv @@ -1,4 +1,4 @@ -var app = 'helix' +var app = 'nvim' var editors = [ &emac=[ diff --git a/aliases/vivaldiprofile.elv b/aliases/vivaldi.elv similarity index 100% rename from aliases/vivaldiprofile.elv rename to aliases/vivaldi.elv diff --git a/aliases/which.elv b/aliases/which.elv new file mode 100644 index 0000000..3b158a0 --- /dev/null +++ b/aliases/which.elv @@ -0,0 +1,28 @@ +fn -aliases {|| + use re + use str + + e:cat $E:HOME/.config/elvish/aliases/*.elv | e:rg '^edit:add-var' | re:awk {|_ _ alias @_| + str:replace '~' '' $alias + } | order +} + +edit:add-var aliases~ {|| -aliases | each {|e| echo $e } } + +edit:add-var which-all~ {|argv| + use framagit.org/benjamin.vaudour/elv-lib/mods/list + use path + use os + use str + + if (-aliases | list:contains $argv) { + echo '(Alias)' + } + + str:split ':' $E:PATH | each {|p| + var f = (path:join $p $argv) + if (os:is-regular $f) { + echo $f + } + } +} diff --git a/rc.elv b/rc.elv index 36ab91e..c3ecb67 100644 --- a/rc.elv +++ b/rc.elv @@ -1,12 +1,12 @@ #set-env BAT_THEME Coldark-Cold set-env BAT_PAGER 'less -RF' set-env EXA_COLORS 'da=36:*.pdf=4:*.doc=4:*.xls=4:*.docx=4:*.xlsx=4:*.odt=4:*.ods=4' -#set-env EDITOR nvim -set-env EDITOR vim +#set-env EDITOR vim +set-env EDITOR nvim #set-env EDITOR kak #set-env EDITOR hx -#set-env VISUAL 'nvim -R' -set-env VISUAL 'vim -R' +#set-env VISUAL 'vim -R' +set-env VISUAL 'nvim -R' #set-env VISUAL 'kak -ro' #set-env VISUAL hx set-env CURRENT_SHELL 'elvish' @@ -14,7 +14,7 @@ set-env STARSHIP_CONFIG ~/.config/starship/starship.toml set-env PERL5LIB /home/benjamin/perl5/lib/perl5 set-env NODE_OPTIONS --openssl-legacy-provider set-env QSV_SNIFF_DELIMITER 1 -set @paths = $@paths /home/benjamin/bin /home/benjamin/Go/bin /home/benjamin/perl5/bin +set @paths = /home/benjamin/{bin,Go/bin,perl5/bin} $@paths { use framagit.org/benjamin.vaudour/elv-lib/mods/list