feat: Created new extension to wrap insert -m

master
NunoSempere 2 years ago
parent 17550da1fa
commit abc527cf88

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

@ -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 if [[ $COMP_CWORD -gt 2 ]]; then
case "${COMP_WORDS[2]}" in case "${COMP_WORDS[2]}" in
help|--help|-h) help|--help|-h)
@ -14,4 +14,4 @@ __password_store_extension_complete_reveal() {
COMPREPLY+=($(compgen -W "help version -h --help -v --version" -- ${cur})) COMPREPLY+=($(compgen -W "help version -h --help -v --version" -- ${cur}))
_pass_complete_entries 1 _pass_complete_entries 1
fi fi
} }
Loading…
Cancel
Save