diff options
author | EuAndreh <eu@euandre.org> | 2022-05-12 21:08:35 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2022-05-12 21:08:59 -0300 |
commit | 78f534b62b8b94b23aa9e73e4c2986d90136c8c6 (patch) | |
tree | 2509fb6bf5fd1b51bf8a85b74b5411a6b3216374 | |
parent | etc/i3status/config: Setup working i3status bar configuration (diff) | |
download | dotfiles-78f534b62b8b94b23aa9e73e4c2986d90136c8c6.tar.gz dotfiles-78f534b62b8b94b23aa9e73e4c2986d90136c8c6.tar.xz |
bin/password: Add executable, a replacement for the genpassword function
-rwxr-xr-x | bin/password | 57 | ||||
-rw-r--r-- | etc/bash/rc | 5 |
2 files changed, 57 insertions, 5 deletions
diff --git a/bin/password b/bin/password new file mode 100755 index 0000000..718ba1c --- /dev/null +++ b/bin/password @@ -0,0 +1,57 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + password [LENGTH] + password -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -h, --help show this message + + LENGTH the size of the password (default: 99) + 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-99}" +tr -cd '[:alnum:]' < /dev/random | + fold -w "$LENGTH" | + head -n1 | + tr -d '\n' diff --git a/etc/bash/rc b/etc/bash/rc index 96c9312..8588089 100644 --- a/etc/bash/rc +++ b/etc/bash/rc @@ -213,11 +213,6 @@ cm() { -genpassword() { - length="${1-99}" - tr -cd '[:alnum:]' < /dev/urandom | fold -w "$length" | head -n1 -} - deps() { cd ~/dev/libre/package-repository/ || return 1 rm -f public/dependencies.svg |