60 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
#!/bin/sh
 | 
						|
 | 
						|
_gpg-unlock
 | 
						|
set -xe
 | 
						|
 | 
						|
find_file() {
 | 
						|
  fd --strip-cwd-prefix '\.gpg$' |
 | 
						|
  sd ".gpg$" "" |
 | 
						|
  wdmenu -p "Password" $@
 | 
						|
}
 | 
						|
 | 
						|
print_actions_for_entry() {
 | 
						|
  echo "Autotype"
 | 
						|
  if test -n "$username"; then
 | 
						|
    echo "Username -> $username"
 | 
						|
  fi
 | 
						|
  echo "Password"
 | 
						|
  if test -n "$otp"; then
 | 
						|
    echo "OTP"
 | 
						|
  fi
 | 
						|
}
 | 
						|
 | 
						|
main() {
 | 
						|
    test -n "$PASSWORD_STORE_DIR" &&
 | 
						|
      cd "$PASSWORD_STORE_DIR" ||
 | 
						|
      cd "$HOME/.password-store"
 | 
						|
 | 
						|
    entry=`find_file "$@"`
 | 
						|
 | 
						|
    test -n "$entry" || exit 0
 | 
						|
 | 
						|
    username=`pass show "$entry" 2>/dev/null | rg -m1 '(login|user|email): (.*)' -r '$2'` || true
 | 
						|
    password=`pass show "$entry" 2>/dev/null | head -n 1` || true
 | 
						|
    otp=`pass otp "$entry" 2>/dev/null` || true
 | 
						|
 | 
						|
    action="$(print_actions_for_entry | wdmenu -p Action)"
 | 
						|
 | 
						|
    case $action in
 | 
						|
        Autotype)
 | 
						|
            autotype
 | 
						|
            ;;
 | 
						|
        Username*)
 | 
						|
            printf '%s' "$username" | wl-copy;;
 | 
						|
        Password)
 | 
						|
            printf '%s' "$password" | wl-copy;;
 | 
						|
        OTP)
 | 
						|
            pass otp "$entry" | wl-copy;;
 | 
						|
    esac
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
autotype(){
 | 
						|
    if test -n "$username"; then
 | 
						|
        env wtype -s 100 "$username"
 | 
						|
        env wtype -s 100 -k tab
 | 
						|
    fi
 | 
						|
    env wtype -s 100 "$password"
 | 
						|
}
 | 
						|
 | 
						|
main
 |