feat(cli): add PJ_STATE env handling for task state communication

This commit is contained in:
Prad Nukala committed 2026-09-30 11:54:12 -04:00
1 parent e9a7fd1fde
commit 19aeed21ac
1 file changed
+8 -1
+8 -1
View File
@@ -16,6 +16,10 @@
# Env:
# PJ_QUIET=1 suppress the "no task sources" error — the down-arrow
# bindings use this, where an empty tree is the normal case.
# PJ_STATE=FILE key bindings pass a path; pj writes `open` to it when the
# picker opens and `pj --run` writes `ran`, so the binding
# can tell "no tasks" / "cancelled" / "task printed output"
# apart and redraw the prompt accordingly (tv --inline).
#
# Cable entry points (tab-separated record fields, see `--list`):
# pj --list print one record per task
@@ -150,6 +154,8 @@ fi
if [ "${1-}" = --run ]; then
kind=${2-} target=${3-} root=${4-} runner=${5-}
cd "$root" || exit 1
# Tell the key binding a task ran (its output now sits below the prompt).
[ -n "${PJ_STATE-}" ] && echo ran >"$PJ_STATE"
# Extra args from `pj a b …`, shell-quoted into $PJ_EXTRA by the picker.
extra=()
@@ -440,4 +446,5 @@ if [ $# -gt 0 ]; then
PJ_EXTRA=$(printf '%q ' "$@")
export PJ_EXTRA
fi
tv pj --source-command "cat '$tmp'" --input-header "$primary"
[ -n "${PJ_STATE-}" ] && echo open >"$PJ_STATE"
tv pj --inline --source-command "cat '$tmp'" --input-header "$primary"