chore: initial commit

This commit is contained in:
technofab 2025-07-19 19:06:52 +02:00
commit c2fe2b6d60
No known key found for this signature in database
2 changed files with 66 additions and 0 deletions

11
README.md Normal file
View file

@ -0,0 +1,11 @@
# GPG Pinentry inside TMUX
See it in action:
[![asciicast](https://asciinema.org/a/UE29nOhgOVwjESVIoj1ftFqWt.svg)](https://asciinema.org/a/UE29nOhgOVwjESVIoj1ftFqWt)
## Installation
1. add your fallback pinentry to `pinentry-tmux.sh`
2. put the shell script in your path, eg. `~/.local/bin/pinentry-tmux` (without `.sh`)
3. configure gpg to use `pinentry-tmux` for pinentry

55
pinentry-tmux.sh Executable file
View file

@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -eo pipefail
# fallback if empty
if [[ -z "$PINENTRY_USER_DATA" ]]; then
# TODO: add your fallback pinentry here
exec <fallback-pinentry> "$@"
fi
if [[ "$PINENTRY_USER_DATA" != "tmux" ]]; then
echo "Unsupported pinentry type in PINENTRY_USER_DATA"
exit 1
fi
DESCFILE=$(mktemp)
cleanup() {
rm -f "$DESCFILE"
}
trap cleanup EXIT
prompt="PIN:"
echo "OK Please go ahead"
while read cmd rest; do
case "$cmd" in
SETDESC)
echo "$(tput setaf 8)$(echo "$rest" | sed -e 's/%0A/\n/g' -e 's/%22/"/g')$(tput sgr0)" > $DESCFILE
echo "OK"
;;
SETPROMPT)
prompt="$(tput smul)$rest$(tput sgr0)"
echo "OK"
;;
GETPIN)
PIPE=$(mktemp -u)
mkfifo "$PIPE"
chmod 600 "$PIPE"
tmux display-popup -w 70 -h 7 -E "bash -c 'cat $DESCFILE; echo -n \"$prompt \"; read -s pw; echo \$pw > $PIPE'" &
PIN=$(<"$PIPE")
rm -f "$PIPE"
echo "D $PIN"
echo "OK"
;;
BYE)
echo "OK"
exit 0
;;
*)
echo "OK"
;;
esac
done