Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. passfor() {
  2. PASS_ACCOUNTS=`pass | tail -n +2 | grep $1`;
  3. if [[ $PASS_ACCOUNTS == '' ]]
  4. then
  5. echo "No pass account found for $1";
  6. return;
  7. fi
  8. ACCOUNT_NAME='';
  9. while read line ; do
  10. # Clean up password data
  11. ACCOUNT_NAME=`echo $line | awk -F " " '{ print $2 }' \
  12. | sed 's/^/./' | rev \
  13. | cut -d. -f2- | rev \
  14. | cut -c2-`
  15.  
  16. # Remove color from pass' output
  17. ACCOUNT_NAME=`echo $ACCOUNT_NAME | sed -E "s,$(printf '\033')\\[[0-9;]*[a-zA-Z],,g"`;
  18. # Get name of the service
  19. EXACT_ACCOUNT_NAME=`echo $ACCOUNT_NAME | cut -d'_' -f 1`;
  20. # If name of the account is matched 100%, show password for this record else show password for last matched account.
  21. # copy password to clipboard
  22. if [[ $EXACT_ACCOUNT_NAME == $1 ]]
  23. then
  24. break;
  25. fi
  26. done <<< $(echo -e "$PASS_ACCOUNTS");
  27. PASS=`pass $ACCOUNT_NAME`;
  28. echo $PASS | pbcopy;
  29. echo "Password for $ACCOUNT_NAME copied to clipboard";
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement