dm-passmenu.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env bash
  2. # Colors:
  3. # # Materia Manjaro
  4. # nf='#09dbc9'
  5. # nb='#222b2e'
  6. # sf='#dbdcd5'
  7. # sb='#009185'
  8. # Everforest
  9. nf='#d3c6aa'
  10. nb='#2d353b'
  11. sf='#a7c080'
  12. sb='#475258'
  13. fn='Iosevka-18:normal'
  14. # fn='Ubuntu-16:normal'
  15. # Gruvbox
  16. # nf='#fea63c'
  17. # nb='#282828'
  18. # # sf='#dbdcd5'
  19. # sb='#d79921'
  20. # fn='Sarasa Mono SC Nerd-17:normal'
  21. # shopt -s nullglob globstar
  22. typeit=0
  23. if [[ $1 == "--type" ]]; then
  24. typeit=1
  25. shift
  26. fi
  27. if [[ -n $WAYLAND_DISPLAY ]]; then
  28. DMENU=dmenu-wl
  29. xdotool="ydotool type --file -"
  30. elif [[ -n $DISPLAY ]]; then
  31. DMENU="dmenu -i -l 10 -nf ${nf} -nb ${nb} -sf ${sf} -sb ${sb} -fn ${fn} -p"
  32. xdotool="xdotool type --clearmodifiers --file -"
  33. else
  34. echo "Error: No Wayland or X11 display detected" >&2
  35. exit 1
  36. fi
  37. prefix=${PASSWORD_STORE_DIR-~/.password-store}
  38. password_files=( "$prefix"/**/*.gpg )
  39. password_files=( "${password_files[@]#"$prefix"/}" )
  40. password_files=( "${password_files[@]%.gpg}" )
  41. # password=$(printf '%s\n' "${password_files[@]}" | "$dmenu" "$@")
  42. password=$(printf '%s\n' "${password_files[@]}" | ${DMENU} 'Password for:')
  43. # password=$(printf '%s\n' "${password_files[@]}" | "$dmenu" -i -l 10 -nf ${nf} -nb ${nb} -sf ${sf} -sb ${sb} -fn ${fn} -p 'Password for:')
  44. [[ -n $password ]] || exit
  45. if [[ $typeit -eq 0 ]]; then
  46. # pass show -c "$password" 2>/dev/null
  47. all_data=$(pass show $password) # because 'pass show' shows all data(url, username, etc) from the file
  48. # got_password=$(echo $(pass show $password) | awk '{print $1}')
  49. if [[ $? == 1 ]]; then
  50. notify-send -t 5000 -i dialog-information "$password doesn't exist."
  51. elif [[ $all_data ]]; then
  52. got_password=$(echo $all_data | awk '{print $1}') # get only password from all_data
  53. for_notify=$(echo $password | cut -d "/" -f2)
  54. echo $got_password | xclip -selection clipboard
  55. notify-send -t 5000 -i dialog-information "Copied $for_notify to clipboard.
  56. Will clear in 45 seconds."
  57. sleep 45
  58. cat /dev/null | xclip -sel clip
  59. notify-send -t 5000 -i dialog-information "Cleared."
  60. else
  61. notify-send -t 5000 -i dialog-information "Bad Passphrase."
  62. fi
  63. else
  64. pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | $xdotool
  65. fi