pass-append

An extension for pass
Log | Files | Refs | README | LICENSE

commit abc527cf88b0d0245ad0ba30c7fa2f17b4a5fde8
parent 17550da1fa10d24ed4a5048cd0069354799d557e
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Mon, 20 Dec 2021 13:47:27 +0100

feat: Created new extension to wrap insert -m

Diffstat:
Aappend.bash | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apass-append.bash.completion | 17+++++++++++++++++
Dpass-reveal.bash.completion | 18------------------
Dreveal.bash | 93-------------------------------------------------------------------------------
4 files changed, 113 insertions(+), 111 deletions(-)

diff --git a/append.bash b/append.bash @@ -0,0 +1,95 @@ +#!/usr/bin/env bash +# pass append - Password Store Extension (https://www.passwordstore.org/) +# Copyright (C) 2021 +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# [] + +VERSION="0.0.1" +PASSWORD_STORE_LOCATION="~/password-store" + +cmd_append_usage() { + cat <<-_EOF +Usage: + $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 append version + Prints the version number. + +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 append.bash ~/.password-store/.extensions +Give the file execution permissions: +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-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_append_version() { + echo $VERSION + exit 0 +} + +cmd_append_append() { + ## [[ $# -gt 1 ]] && die "Too many arguments. At most 1 argument allowed." + + # expect 0 or 1 argument + # ignore 2nd argument and higher + if [ $# -eq 0 ]; then + echo "Error: Query is empty" + else + + ARGS="$@" + 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 +} + +case "$1" in +help | --help | -h) + shift + cmd_append_usage "$@" + ;; +version | --version | -v) + shift + cmd_append_version "$@" + ;; +*) cmd_append_append "$@" ;; +esac +exit 0 +\ No newline at end of file diff --git a/pass-append.bash.completion b/pass-append.bash.completion @@ -0,0 +1,17 @@ +PASSWORD_STORE_EXTENSION_COMMANDS+=(append) + +__password_store_extension_complete_append() { + if [[ $COMP_CWORD -gt 2 ]]; then + case "${COMP_WORDS[2]}" in + help|--help|-h) + _pass_complete_entries + ;; + version|--version|-v) + _pass_complete_entries + ;; + esac + else + COMPREPLY+=($(compgen -W "help version -h --help -v --version" -- ${cur})) + _pass_complete_entries 1 + fi +} diff --git a/pass-reveal.bash.completion b/pass-reveal.bash.completion @@ -1,17 +0,0 @@ -PASSWORD_STORE_EXTENSION_COMMANDS+=(reveal) - -__password_store_extension_complete_reveal() { - if [[ $COMP_CWORD -gt 2 ]]; then - case "${COMP_WORDS[2]}" in - help|--help|-h) - _pass_complete_entries - ;; - version|--version|-v) - _pass_complete_entries - ;; - esac - else - COMPREPLY+=($(compgen -W "help version -h --help -v --version" -- ${cur})) - _pass_complete_entries 1 - fi -} -\ No newline at end of file diff --git a/reveal.bash b/reveal.bash @@ -1,92 +0,0 @@ -#!/usr/bin/env bash -# pass reveal - Password Store Extension (https://www.passwordstore.org/) -# Copyright (C) 2021 -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# [] - -VERSION="0.0.1" -PASSWORD_STORE_LOCATION="~/password-store" - -cmd_reveal_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 - Prints this help message. - $PROGRAM reveal 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 -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 -Give the file execution permissions: -E.g. chmod 700 ~/.password-store/.extensions/reveal.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 -_EOF - exit 0 -} - -cmd_reveal_version() { - echo $VERSION - exit 0 -} - -cmd_reveal_reveal() { - ## [[ $# -gt 1 ]] && die "Too many arguments. At most 1 argument allowed." - - # expect 0 or 1 argument - # ignore 2nd argument and higher - if [ $# -eq 0 ]; then - echo "Error: Query is empty" - 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 - - fi -} - -case "$1" in -help | --help | -h) - shift - cmd_reveal_usage "$@" - ;; -version | --version | -v) - shift - cmd_reveal_version "$@" - ;; -*) cmd_reveal_reveal "$@" ;; -esac -exit 0 -\ No newline at end of file