add (working) password.sh
This commit is contained in:
parent
65119b720a
commit
b21751a790
39
examples/password.sh
Normal file
39
examples/password.sh
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/usr/bin/env shrimp
|
||||||
|
# usage: password <length> [!spaced] [!symbols]
|
||||||
|
|
||||||
|
if ($.args | list.contains? -h):
|
||||||
|
echo 'usage: password <length> [!spaced] [!symbols]'
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
password = do n=22 symbols=true spaced=true:
|
||||||
|
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
||||||
|
if symbols: chars += '!@#%^&*-=()[]<>' end
|
||||||
|
|
||||||
|
out = []
|
||||||
|
i = 0
|
||||||
|
max = length chars
|
||||||
|
|
||||||
|
while i < n:
|
||||||
|
idx = math.floor ((math.random) * max)
|
||||||
|
ch = chars | at idx
|
||||||
|
list.push out ch
|
||||||
|
i += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if spaced:
|
||||||
|
pos1 = math.floor((n - 2) / 3)
|
||||||
|
pos2 = math.floor((n - 2) * 2 / 3)
|
||||||
|
|
||||||
|
list.insert out pos2 ' '
|
||||||
|
list.insert out pos1 ' '
|
||||||
|
end
|
||||||
|
|
||||||
|
str.join out ''
|
||||||
|
end
|
||||||
|
|
||||||
|
missing-arg? = do x: $.args | list.contains? x | not end
|
||||||
|
|
||||||
|
num = $.args | list.reject (do x: x | str.starts-with? ! end) | list.first
|
||||||
|
|
||||||
|
password num symbols=(missing-arg? !symbols) spaced=(missing-arg? !spaced) | echo
|
||||||
Loading…
Reference in New Issue
Block a user