summaryrefslogtreecommitdiff
path: root/pass.sh
diff options
context:
space:
mode:
Diffstat (limited to 'pass.sh')
-rwxr-xr-xpass.sh48
1 files changed, 48 insertions, 0 deletions
diff --git a/pass.sh b/pass.sh
new file mode 100755
index 0000000..c8cd0de
--- /dev/null
+++ b/pass.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-3.0-or-later
+# SPDX-FileCopyrightText: Copyright 2021 Aleksei Kovura
+[ -z "$PASSWORD_STORE_DIR_PLAIN" ] && {
+ printf "set \$PASSWORD_STORE_DIR_PLAIN first\n"
+ exit 1
+}
+#[ ! -d "$PASSWORD_STORE_DIR_PLAIN" ] && {
+ #printf "%s is not a directory\n" "$PASSWORD_STORE_DIR_PLAIN"
+ #exit 1
+#}
+PASSWORD_STORE_DIR_PLAIN=$HOME/passwords-plain
+name_to_file() {
+ file="${PASSWORD_STORE_DIR_PLAIN}/${1}.pass"
+ printf "%s\n" $file
+}
+name_is_in_repo() {
+ [ -z "$1" ] && printf "%s\n" "provide name" 1>&2 && return 1
+ file="${PASSWORD_STORE_DIR_PLAIN}/${1}.pass"
+ [ ! -f $file ] && printf "%s not in repo\n" $1 1>&2 && return 1
+ return 0
+}
+case $1 in
+ edit)
+ [ -z "$EDITOR" ] && printf "\$EDITOR is not set\n" && exit 1
+ name_is_in_repo $2 && $EDITOR $(name_to_file $2)
+ ;;
+ show)
+ name_is_in_repo $2 && cat $(name_to_file $2)
+ ;;
+ list|ls|"")
+ basename -a -s '.pass' $PASSWORD_STORE_DIR_PLAIN/*.pass
+ ;;
+ generate)
+ name_is_in_repo $2 && printf "%s already exists\n" $2 && exit 1
+ command -v pwgen 1>/dev/null && {
+ pwgen -cns1 25 | tee $PASSWORD_STORE_DIR_PLAIN/${2}.pass
+ } || printf "need pwgen installed" && exit 1
+ ;;
+ remove|rm|delete)
+ [ -z "$2" ] && printf "%s\n" "provide name" && exit 1
+ file=$(name_to_file $2)
+ rm -iv $file
+ ;;
+ *)
+ printf "%s is not implemented\n" "$1"
+ ;;
+esac