28 lines
		
	
	
		
			630 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			630 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
| #!/usr/bin/env bash
 | |
| 
 | |
| # Fetches the FIELD in ENTRY. It expects pass fields to be colon-delimited.
 | |
| 
 | |
| if (( $# != 2 )); then
 | |
|   >&2 echo "Expected two arguments"
 | |
|   >&2 echo "pass get ENTRY FIELD"
 | |
|   exit 1
 | |
| fi
 | |
| 
 | |
| entry=$1
 | |
| field=$2
 | |
| 
 | |
| secrets="$(pass show $entry)"
 | |
| if [[ ! $secrets ]]; then
 | |
|   notify-send --urgency=critical "Failed to retrieve $entry"
 | |
|   exit 2
 | |
| fi
 | |
| 
 | |
| case $field in
 | |
|   password) printf "%s" "$(head -n1 <<<"$secrets")" ;;
 | |
|   otp) printf "%s" "$(pass otp "$entry")" ;;
 | |
|   *) printf "%s" "$(awk -v "key=$field:" '$1 == key {print $2}' <<<"$secrets")" ;;
 | |
| esac | xsel -i -b -t 15000
 | |
| 
 | |
| #
 | |
| echo "Copied $entry:$field to clipboard for 15s"
 |