Retrieve pass store secrets in Python, Bash and Perl scripts

(, en)

One of the major advantages of Pass: The Standard Unix Password Manager is its interoperability. You can basically call it from anywhere. Basically also means that there might be a catch: I use the ncurses version of pinentry on the console. If you call pass from a script it needs to be able to start pinentry and show the dialog to enter the passphrase for the password store. Here are my snippets to get it working in Bash, Python and Perl:

Bash

PASS_FIRST=$(pass show secret | head -n 1)
echo ">>$PASS_FIRST<<"

PASS_MULTI=$(pass show secret)
echo ">>>"
echo "$PASS_MULTI"
echo "<<<"

Python

(Python was more tricky than expected, but this works)

import subprocess as sp

res = (
    sp.run("pass show secret", shell=True, stdout=sp.PIPE)
    .stdout.decode("utf-8", "replace")
    .splitlines()[0]
)
print(f">>{res}<<")

Perl

use warnings;
use utf8;
use 5.30.0;

my $pass = qx#pass show secret#;
$pass = (split /\n/, $pass)[0];
say ">>$pass<<";