commit 215100d29383cb4777b9b672a2d7b27a9b718e5b
parent dae217b7dd0e50fd931e4ad4af03de1c66363877
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date: Wed, 12 Oct 2022 14:37:08 +0200
Status file for zshaskpass_lock
Diffstat:
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/bin/zshaskpass_lock b/bin/zshaskpass_lock
@@ -74,6 +74,11 @@ nag() {
background ' i3-nagbar' ' -f' ' fixed' " $^@" ""
}
+set-statefile() {
+ mkdir -p /run/user/$USER/i3status &&
+ printf "%s\n" $@ >/run/user/$USER/i3status/${TTY:t}
+}
+
logincap() {
if ! (( $+LOGINCAP_READFD & $+LOGINCAP_WRITEFD )); then
echo "logincap FDs not defined"
@@ -89,11 +94,13 @@ logincap() {
lock() {
plumb zsh-history # This is a good spot to synchronize history in absence of fs watcher
+ set-statefile lock
ssh-add -D || die "Error removing identities"
s6-svc -o -wu -T 3000 $x_container_tmpfs/run/service/screen-locker/ || "Failed to bring up screen locker"
s6-svstat $x_container_tmpfs/run/service/screen-locker/
s6-svlisten1 -d $x_container_tmpfs/run/service/screen-locker/ zsh -c "read -sk 1 $'?\e[1mSession locked\e[m, press enter to unlock.\n' || exit 98; until ssh-add -c; do sleep 2; read -sk 1 $'?\nUnlock failed, press enter to try again.\n' || exit 98; done; if ssh-add -l >/dev/null; then printf '%s\n' 'Success, stopping screen locker'; s6-svc -d '$x_container_tmpfs/run/service/screen-locker/'; fi"
ssh-add -l >/dev/null || die "Failed to load SSH agent identities (screen locker died?), exiting."
+ set-statefile
}
setup-plumber-listener() {
@@ -153,16 +160,26 @@ cmd() {
lock
;;
(exit)
+ set-statefile exit
true >/run/user/$USER/X$X/fifo
logincap stopX\ $X
keep_running=0
;;
(shell)
- zsh -li; printf "shell exited with %d\n" $?;;
+ set-statefile shell
+ zsh -li; printf "shell exited with %d\n" $?
+ set-statefile
+ ;;
(cleanshell)
- run zsh -li; printf "shell exited with %d\n" $?;;
+ set-statefile cleanshell
+ run zsh -li; printf "shell exited with %d\n" $?
+ set-statefile
+ ;;
(tmux)
- run tmux -u new-session -A -s ${TTY:t} ; printf "tmux exited with %d\n" $?;;
+ set-statefile tmux
+ run tmux -u new-session -A -s ${TTY:t} ; printf "tmux exited with %d\n" $?
+ set-statefile
+ ;;
(*) printf '%s: unknown command\n' ${(qqq)REPLY};;
esac
}
@@ -243,21 +260,26 @@ trap 'printf "\nALRM!\n"' ALRM
exec {COPROC_OUT}<& p
select_fds=( $ZSHASKPASS_PROMPTFD $COPROC_OUT )
+set-statefile
keep_running=1
while (($keep_running)) && zselect -A fds -r 0 $select_fds; do
+ set-statefile
if ! (($#jobstates)); then
echo >&2 "Session exited."
+ set-statefile exit
exit 0
fi
for fd in ${(k)fds}; do
if [[ $fds[$fd] != r ]]; then
echo >&2 "Error on filedescriptor $fd"
+ set-statefile error-on-fd-$fd
exit 1
fi
if [[ $fd == $ZSHASKPASS_PROMPTFD ]]; then
# zshaskpass
if IFS= read -u $fd; then
if [[ $REPLY == *': ' ]]; then
+ set-statefile "askpass: $REPLY"
printf '%s' "$REPLY${(%)prompt_end}"
read -s
RET=$?