#!/bin/sh # # Reads STDIN ensuring protocol=https (if present) and then until the # line host= is found. Finally, uses to look through # login info to then output credentials for git. LOGINS_DB=$HOME/.config/logins.db.asc # We only support get as the first argument if [ $1 != "get" ]; then exit 1 fi # Read input to figure out which host/domain we want to read # credentials from export LESSPASS_MASTER_PASSWORD=`pass lesspass` SELECTION= while read input; do key=`echo $input | cut -f 1 -d '='` value=`echo $input | cut -f 2 -d '='` if [ $key == 'protocol' ] && [ $value != 'https' ]; then exit 1 fi if [ $key == 'host' ]; then SELECTION=`gpg --decrypt $LOGINS_DB 2>/dev/null | grep $value` break fi done if [ -z "${SELECTION}" ]; then exit 1 fi DOMAIN=`echo $SELECTION | cut -f 1 -d ' '` USERNAME=`echo $SELECTION | cut -f 2 -d ' '` OPTIONS=`echo $SELECTION | cut -f 1,2 -d ' ' --complement` # Output credentials in the format git expects echo protocol=https echo host=$DOMAIN echo username=$USERNAME echo password=`lpass $DOMAIN $USERNAME $OPTIONS`