From abc527cf88b0d0245ad0ba30c7fa2f17b4a5fde8 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Mon, 20 Dec 2021 13:47:27 +0100 Subject: [PATCH] feat: Created new extension to wrap insert -m --- reveal.bash => append.bash | 67 ++++++++++--------- ....completion => pass-append.bash.completion | 6 +- 2 files changed, 38 insertions(+), 35 deletions(-) rename reveal.bash => append.bash (52%) rename pass-reveal.bash.completion => pass-append.bash.completion (77%) diff --git a/reveal.bash b/append.bash similarity index 52% rename from reveal.bash rename to append.bash index 5439360..97109fc 100644 --- a/reveal.bash +++ b/append.bash @@ -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 \ No newline at end of file diff --git a/pass-reveal.bash.completion b/pass-append.bash.completion similarity index 77% rename from pass-reveal.bash.completion rename to pass-append.bash.completion index b896d05..150d6a8 100644 --- a/pass-reveal.bash.completion +++ b/pass-append.bash.completion @@ -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 -} \ No newline at end of file +}