feat: Created new extension to wrap insert -m

This commit is contained in:
NunoSempere 2021-12-20 13:47:27 +01:00
parent 17550da1fa
commit abc527cf88
2 changed files with 38 additions and 35 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
# pass reveal - Password Store Extension (https://www.passwordstore.org/)
# pass append - Password Store Extension (https://www.passwordstore.org/)
# Copyright (C) 2021
#
# This program is free software: you can redistribute it and/or modify
@ -19,43 +19,42 @@
VERSION="0.0.1"
PASSWORD_STORE_LOCATION="~/password-store"
cmd_reveal_usage() {
cmd_append_usage() {
cat <<-_EOF
Usage:
$PROGRAM reveal [search-terms]
Searches and displays passwords from \$PASSWORD_STORE_LOCATION.
A simple wrapper over pass show, find, and grep.
Based on the pass reveal extension.
$PROGRAM reveal help
$PROGRAM append [filename]
Generates a strong password, copies it to the clipboard, and runs pass insert -m [filename]
Based on the pass reveal extension, itself based on the pass backup extension.
$PROGRAM append help
Prints this help message.
$PROGRAM reveal version
$PROGRAM append version
Prints the version number.
Example: $PROGRAM reveal web
Searches for any files in $PASSWORD_STORE_LOCATION whose filenames contain
the keyword "web"
For installation place this bash script file "reveal.bash" into
Example: $PROGRAM append services/amazon
Generates a strong password, copies it to the clipboard,
and starts pass insert -m services/amazon
For installation place this bash script file "append.bash" into
the passwordstore extension directory specified with \$PASSWORD_STORE_EXTENSIONS_DIR.
By default this is ~/.password-store/.extensions.
E.g. cp reveal.bash ~/.password-store/.extensions
E.g. cp append.bash ~/.password-store/.extensions
Give the file execution permissions:
E.g. chmod 700 ~/.password-store/.extensions/reveal.bash
E.g. chmod 700 ~/.password-store/.extensions/append.bash
Set the variable PASSWORD_STORE_ENABLE_EXTENSIONS to true to enable extensions.
E.g. export PASSWORD_STORE_ENABLE_EXTENSIONS=true
Source the bash completion file "pass-reveal.bash.completion" for bash completion.
E.g. source ~/.password-store/.bash-completions/pass-reveal.bash.completion
Type "pass reveal query" to make your first query
E.g. pass reveal query
Source the bash completion file "pass-append.bash.completion" for bash completion.
E.g. source ~/.password-store/.bash-completions/pass-append.bash.completion
Type "pass append query" to make your first query
E.g. pass append query
_EOF
exit 0
}
cmd_reveal_version() {
cmd_append_version() {
echo $VERSION
exit 0
}
cmd_reveal_reveal() {
cmd_append_append() {
## [[ $# -gt 1 ]] && die "Too many arguments. At most 1 argument allowed."
# expect 0 or 1 argument
@ -65,15 +64,19 @@ cmd_reveal_reveal() {
else
ARGS="$@"
BEST_FIT="$(find ~/.password-store -type f -printf "%P\n" | grep -v '^\.' | grep -i "$ARGS" | sed 's/.gpg//' | head -1)"
if [ -z "$BEST_FIT" ]; then
# $STRING is empty
echo "No match found for $ARGS"
else
echo "Best match: $BEST_FIT"
pass show "$BEST_FIT"
pass show -c "$BEST_FIT"
fi
charstring1='"'
charstring2="\!#\$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_\`abcdefghijklmnopqrstuvwxyz{|}~"
characters="$charstring1$charstring2"
length=25
read -r -n $length new_password < <(LC_ALL=C tr -dc "$characters" < /dev/urandom)
printf "$new_password" | xclip -sel clip
echo "Copied new password to clipboard: "
echo "$new_password"
pass insert -m "$ARGS"
fi
}
@ -81,12 +84,12 @@ cmd_reveal_reveal() {
case "$1" in
help | --help | -h)
shift
cmd_reveal_usage "$@"
cmd_append_usage "$@"
;;
version | --version | -v)
shift
cmd_reveal_version "$@"
cmd_append_version "$@"
;;
*) cmd_reveal_reveal "$@" ;;
*) cmd_append_append "$@" ;;
esac
exit 0

View File

@ -1,6 +1,6 @@
PASSWORD_STORE_EXTENSION_COMMANDS+=(reveal)
PASSWORD_STORE_EXTENSION_COMMANDS+=(append)
__password_store_extension_complete_reveal() {
__password_store_extension_complete_append() {
if [[ $COMP_CWORD -gt 2 ]]; then
case "${COMP_WORDS[2]}" in
help|--help|-h)
@ -14,4 +14,4 @@ __password_store_extension_complete_reveal() {
COMPREPLY+=($(compgen -W "help version -h --help -v --version" -- ${cur}))
_pass_complete_entries 1
fi
}
}