Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- passfor() {
- PASS_ACCOUNTS=`pass | tail -n +2 | grep $1`;
- if [[ $PASS_ACCOUNTS == '' ]]
- then
- echo "No pass account found for $1";
- return;
- fi
- ACCOUNT_NAME='';
- while read line ; do
- # Clean up password data
- ACCOUNT_NAME=`echo $line | awk -F " " '{ print $2 }' \
- | sed 's/^/./' | rev \
- | cut -d. -f2- | rev \
- | cut -c2-`
- # Remove color from pass' output
- ACCOUNT_NAME=`echo $ACCOUNT_NAME | sed -E "s,$(printf '\033')\\[[0-9;]*[a-zA-Z],,g"`;
- # Get name of the service
- EXACT_ACCOUNT_NAME=`echo $ACCOUNT_NAME | cut -d'_' -f 1`;
- # If name of the account is matched 100%, show password for this record else show password for last matched account.
- # copy password to clipboard
- if [[ $EXACT_ACCOUNT_NAME == $1 ]]
- then
- break;
- fi
- done <<< $(echo -e "$PASS_ACCOUNTS");
- PASS=`pass $ACCOUNT_NAME`;
- echo $PASS | pbcopy;
- echo "Password for $ACCOUNT_NAME copied to clipboard";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement