Compatibilité elvish 0.17

This commit is contained in:
Benjamin VAUDOUR 2021-12-11 21:09:02 +00:00
parent be84588373
commit 87eb82a791
43 changed files with 323 additions and 322 deletions

View file

@ -1,44 +1,44 @@
use str
use re
fn -bytes [begin size]{
fn -bytes {|begin size|
str:from-codepoints (range $begin (+ $begin $size))
}
fn -upper []{
fn -upper {||
-bytes 0x41 26
}
fn -lower []{
fn -lower {||
-bytes 0x61 26
}
fn -digit []{
fn -digit {||
-bytes 0x30 10
}
fn -j [@strings]{
fn -j {|@strings|
str:join '' $strings
}
fn -alpha []{
fn -alpha {||
-j (-upper) (-lower)
}
fn -alphanum []{
fn -alphanum {||
-j (-alpha) (-digit)
}
fn -random [chars]{
fn -random {|chars|
var size = (count $chars)
print $chars[(randint 0 $size)]
}
fn -is-int [arg]{
fn -is-int {|arg|
re:match '^\d+$' $arg
}
fn -help []{
fn -help {||
echo 'Génère une chaîne de caractères aléatoires'
echo 'Usage: genstr [(-auldh)] [<chars>] [<size>]'
echo ''
@ -54,9 +54,9 @@ fn -help []{
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]{
edit:add-var genstr~ {|@args|
var len chars h = 0 '' $false
each [e]{
each {|e|
if (or (eq $e -h) (eq $e --help)) {
set h = $true
-help
@ -86,7 +86,7 @@ edit:add-var genstr~ [@args]{
set chars = [(str:split '' $chars)]
range $len | each [_]{
range $len | each {|_|
-random $chars
}
echo