mirror of
https://gitlab.com/TECHNOFAB/tmux-pinentry.git
synced 2025-12-12 10:10:08 +01:00
chore: initial commit
This commit is contained in:
commit
c2fe2b6d60
2 changed files with 66 additions and 0 deletions
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