pass-append

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

append.bash (3209B)


      1 #!/usr/bin/env bash
      2 # pass append - Password Store Extension (https://www.passwordstore.org/)
      3 # Copyright (C) 2021
      4 #
      5 #    This program is free software: you can redistribute it and/or modify
      6 #    it under the terms of the GNU General Public License as published by
      7 #    the Free Software Foundation, either version 3 of the License, or
      8 #    (at your option) any later version.
      9 #
     10 #    This program is distributed in the hope that it will be useful,
     11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 #    GNU General Public License for more details.
     14 #
     15 #    You should have received a copy of the GNU General Public License
     16 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 # []
     18 
     19 VERSION="0.0.1"
     20 PASSWORD_STORE_LOCATION="~/password-store"
     21 
     22 cmd_append_usage() {
     23   cat <<-_EOF
     24 Usage:
     25     $PROGRAM append [filename]
     26       Generates a strong password, copies it to the clipboard, and runs pass insert -m [filename]
     27           Based on the pass reveal extension, itself based on the pass backup extension.
     28     $PROGRAM append help
     29         Prints this help message.
     30     $PROGRAM append version
     31         Prints the version number.
     32 
     33 Example: $PROGRAM append services/amazon
     34         Generates a strong password, copies it to the clipboard, 
     35         and starts pass insert -m services/amazon
     36 For installation place this bash script file "append.bash" into
     37 the passwordstore extension directory specified with \$PASSWORD_STORE_EXTENSIONS_DIR.
     38 By default this is ~/.password-store/.extensions.
     39 E.g. cp append.bash ~/.password-store/.extensions
     40 Give the file execution permissions:
     41 E.g. chmod 700 ~/.password-store/.extensions/append.bash
     42 Set the variable PASSWORD_STORE_ENABLE_EXTENSIONS to true to enable extensions.
     43 E.g. export PASSWORD_STORE_ENABLE_EXTENSIONS=true
     44 Source the bash completion file "pass-append.bash.completion" for bash completion.
     45 E.g. source ~/.password-store/.bash-completions/pass-append.bash.completion
     46 Type "pass append query" to make your first query
     47 E.g. pass append query
     48 _EOF
     49   exit 0
     50 }
     51 
     52 cmd_append_version() {
     53   echo $VERSION
     54   exit 0
     55 }
     56 
     57 cmd_append_append() {
     58   ## [[ $# -gt 1 ]] && die "Too many arguments. At most 1 argument allowed."
     59 
     60   # expect 0 or 1 argument
     61   # ignore 2nd argument and higher
     62   if [ $# -eq 0 ]; then
     63    echo "Error: Query is empty"
     64   else
     65 
     66     ARGS="$@"
     67 
     68 		# old method of generating a password:
     69     # charstring1='"'
     70     # charstring2="\!#\$&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_\`abcdefghijklmnopqrstuvwxyz{|}~"
     71     # characters="$charstring1$charstring2"
     72     # length=25
     73     # read -r -n $length new_password < <(LC_ALL=C tr -dc "$characters" < /dev/urandom)
     74     
     75 		# new method:
     76     new_password=$(cat /usr/share/dict/words | sed "s|'s||g" | shuf -n6 | sed -z 's/\n/-/g;s/-$/\n/' | tr '[:upper:]' '[:lower:]')
     77     printf "$new_password" | xclip -sel clip
     78     echo "Copied new password to clipboard: "
     79     echo "$new_password"
     80 
     81     pass insert -m "$ARGS"
     82 
     83   fi
     84 }
     85 
     86 case "$1" in
     87 help | --help | -h)
     88   shift
     89   cmd_append_usage "$@"
     90   ;;
     91 version | --version | -v)
     92   shift
     93   cmd_append_version "$@"
     94   ;;
     95 *) cmd_append_append "$@" ;;
     96 esac
     97 exit 0