Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. PATH_TO_PASS=/usr/local/bin/pass
  4. PATH_TO_PASS_DIR=/Users/raam/.password-store
  5. PATH_TO_FIND=/usr/bin/find
  6.  
  7. # Trims ".password-store/Personal/example.com.gpg" to
  8. # "Personal/example.com" for use with the pass command
  9.  
  10. OFFSET=${#PATH_TO_PASS_DIR}
  11. SEARCH_PATTERN=$(echo $1 | sed 's/ /.*/g')
  12. SEARCH_PATTERN=".*$SEARCH_PATTERN.*"
  13.  
  14. # If more than one result was returned by the search,
  15. # we need to present a list of results instead of using
  16. # pass to get the password. If we can, we use the pass
  17. # program to display the results so they look pretty.
  18. NUMBER_OF_RESULTS=$(find $PATH_TO_PASS_DIR -iregex "$SEARCH_PATTERN" | wc -l)
  19. if [ $NUMBER_OF_RESULTS -gt 1 ]; then
  20. SEARCHTERM=$(find $PATH_TO_PASS_DIR -type d -iregex "$SEARCH_PATTERN")
  21.  
  22. # If the search did not return a directory, then we can't
  23. # use the pass program to display teh results and we'll
  24. # need to simply output the result of the find command.
  25. if [ -z "$SEARCHTERM" ] || [ "$SEARCHTERM" == "" ]; then
  26. find $PATH_TO_PASS_DIR -iregex "$SEARCH_PATTERN"
  27. exit
  28. fi
  29.  
  30. # Show the results using the pass program.
  31. PREFIX_TRIMMED=${SEARCHTERM:OFFSET:999}
  32. PREFIX_AND_EXTENSION_TRIMMED="${PREFIX_TRIMMED%.*}"
  33. echo $PREFIX_AND_EXTENSION_TRIMMED
  34. $PATH_TO_PASS show $PREFIX_AND_EXTENSION_TRIMMED
  35. exit
  36. fi
  37.  
  38. # If we got this far, then we found 1 and only 1 result.
  39. # Let's display the password using the pass program.
  40. SEARCHTERM=$(find $PATH_TO_PASS_DIR -iregex "$SEARCH_PATTERN")
  41. PREFIX_TRIMMED=${SEARCHTERM:OFFSET:999}
  42. PREFIX_AND_EXTENSION_TRIMMED="${PREFIX_TRIMMED%.*}"
  43. echo $PREFIX_AND_EXTENSION_TRIMMED
  44. $PATH_TO_PASS show $PREFIX_AND_EXTENSION_TRIMMED
  45. $PATH_TO_PASS show -c $PREFIX_AND_EXTENSION_TRIMMED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement