From 3b937958ac383b05761c9a16bcf5cc9003cd6031 Mon Sep 17 00:00:00 2001 From: Shokara Kou Date: Thu, 13 Oct 2022 19:04:45 -0400 Subject: add generate function and contrib/random script I sometimes forget to copy-paste the passwords and usernames I generate, so this should help with that. Uses the random string generator script I made before by default. --- .gitignore | 1 + README | 6 +++++- angou | 11 ++++++++++- contrib/random | 22 ++++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100755 contrib/random diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/README b/README index 08521d1..d6d1d42 100644 --- a/README +++ b/README @@ -12,6 +12,10 @@ Dependencies - can possibly be replaced with ls if you add ANGOU_LIST in your ~/.profile - xsel (for copying password to clipboard, but can be changed to a different command with the ANGOU_CLIPBOARD command that accepts stdin) +- a password generator + - script uses contrib/random from this repo by default and expects it in your + path + - can change by setting ANGOU_GEN_USER and ANGOU_GEN_PASS in your ~/.profile Configuration ------------- @@ -42,4 +46,4 @@ Set the ANGOU_DIR environment variable to your password store directory. Auto-complete ------------- If you use ksh, all you'd have to do is source contrib/autocomplete.ksh in your -kshrc. \ No newline at end of file +kshrc. diff --git a/angou b/angou index 845670b..c1d06fc 100755 --- a/angou +++ b/angou @@ -6,6 +6,9 @@ ANGOU_DIR=${ANGOU_DIR:-"$HOME/.angou/"} ANGOU_CLIPBOARD=${ANGOU_CLIPBOARD:-"xsel -i"} # sets command to use when listing directory structure ANGOU_LIST=${ANGOU_LIST:-"tree"} +# custom command for generating passwords/users +ANGOU_GEN_PASS=${ANGOU_GEN_PASS:-"random pass"} +ANGOU_GEN_USER=${ANGOU_GEN_USER:-"random user"} mkdir -p "$ANGOU_DIR" cd "$ANGOU_DIR" || exit @@ -35,6 +38,11 @@ edit() { tmpfile="$(mktemp)" + if [ "$2" = "generate" ]; then + $ANGOU_GEN_PASS >"$tmpfile" + echo "Username: $($ANGOU_GEN_USER)" >>"$tmpfile" + fi + # edit a copy of a password if it already exists [ -f "$1" ] && $ANGOU_DECRYPT "$1" > "$tmpfile" @@ -46,7 +54,7 @@ edit() { # print usage usage() { - printf "Usage: %s [help|copy|edit|view [file or directory]]\n" "$0" + printf "Usage: %s [help|copy|edit|generate|view [file or directory]]\n" "$0" printf "\tThe edit and copy command expects a file as an argument,\n" printf "\twhile the view command expects a directory as an argument.\n" printf "\tThe arguments for view and edit are relative to\n" @@ -61,6 +69,7 @@ case "$option" in help) usage ;; copy) copy "$2" ;; edit) edit "$2" ;; + generate) edit "$2" generate ;; view) view "$2" ;; *) view "$1" ;; esac diff --git a/contrib/random b/contrib/random new file mode 100755 index 0000000..10ddda7 --- /dev/null +++ b/contrib/random @@ -0,0 +1,22 @@ +#!/bin/sh +# Simple random string generator for passwords and usernames +# $LEN initial declaration commented out for runtime LEN config + +LC_ALL=C +#LEN=${LEN:-24} +ALPHA="A-Za-z" +NUM="0-9" +SPECIAL='!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' + +random() { + /dev/null ; echo +} + +case $1 in + pass) + random ;; + user) + LEN=${LEN:-12} SPECIAL='' random ;; + *) + printf "Usage: $0 pass|user\nSet LEN environment variable for length" ;; +esac -- cgit v1.2.3