#!/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