1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 22:57:46 +00:00

Enhance by getting length of symbol string (#458)

The get-random-symbol function had a hard coded upper limit when using
"random integer". Switch to getting the length of the symbol string
automatically, so user does not have to physically count
This commit is contained in:
Rick Cogley 2023-04-23 20:45:56 +09:00 committed by GitHub
parent 822005fca6
commit bfa41311ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@
# Updates: 20230415 - initial version
# 20230416 - added @amtoine's slick probabilistic "random decimal" char capitalization
# 20230417 - added script duration output in debug block
# 20230421 - added length of symbol chars to get-random-symbol function
#======= NUPASS PASSWORD GENERATOR =======
# Generate password of 3 dictionary file words, numbers and symbols
@ -27,11 +28,13 @@ export def main [
let randword3 = ($dictfile | get-random-word $word_length $num_lines | random-format-word)
# Get some symbols to sprinkle like salt bae
let symbol_chars = "!@#$%^&*()_-+[]"
let symb1 = (get-random-symbol $symbol_chars)
let symb2 = (get-random-symbol $symbol_chars)
let symb3 = (get-random-symbol $symbol_chars)
let symb4 = (get-random-symbol $symbol_chars)
# Update symbol chars as needed
let symbol_chars = "!@#$%^&()_-+[]{}"
let symbol_chars_len = ($symbol_chars | str length)
let symb1 = (get-random-symbol $symbol_chars $symbol_chars_len)
let symb2 = (get-random-symbol $symbol_chars $symbol_chars_len)
let symb3 = (get-random-symbol $symbol_chars $symbol_chars_len)
let symb4 = (get-random-symbol $symbol_chars $symbol_chars_len)
# Print some vars if debug flag is set
if $debug {
@ -85,8 +88,9 @@ def random-format-word [] {
# Function to get random symbol from list of symbols
def get-random-symbol [
symbolchars: string
symbolcharslen: int
] {
$symbolchars
| split chars
| get (random integer 0..14)
| get (random integer 0..($symbolcharslen - 1))
}