aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-08-13 09:48:49 -0300
committerEuAndreh <eu@euandre.org>2022-08-13 09:48:49 -0300
commitc043cecbf8c28e1a26f940ec49dad59b833e5388 (patch)
tree10b40cd60f5dc58749486c76a5f92eb09f0b64e6 /bin
parentbin/untill: Add working utility (diff)
downloaddotfiles-c043cecbf8c28e1a26f940ec49dad59b833e5388.tar.gz
dotfiles-c043cecbf8c28e1a26f940ec49dad59b833e5388.tar.xz
bin/gen-password: Add working utility
Diffstat (limited to 'bin')
-rwxr-xr-xbin/gen-password73
1 files changed, 73 insertions, 0 deletions
diff --git a/bin/gen-password b/bin/gen-password
new file mode 100755
index 0000000..b59213c
--- /dev/null
+++ b/bin/gen-password
@@ -0,0 +1,73 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ gen-password [LENGTH]
+ gen-password -h
+ EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -h, --help show this message
+
+ LENGTH the length of the generated password
+ (default: 999)
+
+
+ Generate a random password, and emit it to STDOUT.
+
+
+ Examples:
+
+ Create a file with a secret:
+
+ $ gen-password > secret.txt
+
+
+ Generate an absurdly long secret:
+
+ $ gen-password 9999 > giant-secret.txt
+ EOF
+}
+
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+LENGTH="${1:-999}"
+
+tr -cd '[:alnum:]' < /dev/random |
+ fold -w "$LENGTH" |
+ head -n1