#!/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 . # [] 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="$@" # old method of generating a password: # charstring1='"' # charstring2="\!#\$&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_\`abcdefghijklmnopqrstuvwxyz{|}~" # characters="$charstring1$charstring2" # length=25 # read -r -n $length new_password < <(LC_ALL=C tr -dc "$characters" < /dev/urandom) # new method: new_password=$(cat /usr/share/dict/words | sed "s|'s||g" | shuf -n6 | sed -z 's/\n/-/g;s/-$/\n/' | tr '[:upper:]' '[:lower:]') 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