diff --git a/examples/password.sh b/examples/password.sh new file mode 100644 index 0000000..5f858ac --- /dev/null +++ b/examples/password.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env shrimp +# usage: password [!spaced] [!symbols] + +if ($.args | list.contains? -h): + echo 'usage: password [!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 \ No newline at end of file