kasi

POSIX shell password manager that is cryptography program-agnostic
Log | Files | Refs | README | LICENSE

commit 3b937958ac383b05761c9a16bcf5cc9003cd6031
parent 32341a174c86712cabb9243caf9e88f4d7feec50
Author: Shokara Kou <kou@13f0.net>
Date:   Thu, 13 Oct 2022 19:04:45 -0400

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.

Diffstat:
A.gitignore | 1+
MREADME | 7+++++--
Mangou | 11++++++++++-
Acontrib/random | 22++++++++++++++++++++++
4 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +*~ diff --git 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 @@ -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 @@ -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/urandom tr -dc "${ALPHA}${NUM}${SPECIAL}" | /bin/dd bs=1 count=${LEN:-32} 2>/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