dotfiles/config/nix/scripts/cached_pass
Geoffrey Frogeye 1f61ceb395
nix: Migrate scripts
They're a bit slower to start :(.
Hopefully this is something that flakes will help with,
otherwise I'll find another way.
2023-11-26 21:04:58 +01:00

31 lines
495 B
Plaintext
Executable file

#!/usr/bin/env nix-shell
#! nix-shell -i bash
#! nix-shell -p bash pass libnotify
# 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 [ ! -s "${file}" ]
then
notify-send -u low "cached_pass" "Asking to cache: ${name}"
pass ${name} > "${file}"
fi
cat "${file}"