dotfiles/config/scripts/cached_pass

30 lines
462 B
Plaintext
Raw Normal View History

2021-06-11 21:42:55 +02:00
#!/usr/bin/env bash
# TODO Password changed?
set -euo pipefail
if [[ $# -ne 1 ]]
then
echo "Usage: $0 pass-name"
exit 2
fi
name="$1"
BASEDIR="/tmp/cached_pass_${UID}"
mkdir -p "$BASEDIR"
chmod 700 "$BASEDIR"
name_base64="$(echo "$name" | base64)"
file="${BASEDIR}/${name_base64}"
if [ ! -f "${file}" ]
then
pass="$(pass ${name} | head -1)"
echo -n $pass > "${file}"
notify-send -u low "cached_pass" "Cached: ${name}"
fi
cat "${file}"