mirror of
https://gitlab.com/TECHNOFAB/tmux-pinentry.git
synced 2025-12-11 01:30:10 +01:00
chore: initial commit
This commit is contained in:
commit
c2fe2b6d60
2 changed files with 66 additions and 0 deletions
11
README.md
Normal file
11
README.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# GPG Pinentry inside TMUX
|
||||
|
||||
See it in action:
|
||||
[](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
55
pinentry-tmux.sh
Executable 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue