fish hook: `devenv shell` exit via `cd` emits codes to terminal
Describe the bug
When using the standard fish hook, and within an activated devenv shell, exiting via cd changes the directory, but emits control codes to the terminal e.g. ^[]11;rgb:f2f2/.... This started recently for me. Aside from upgrading devenv, I haven't changed anything else about my fish setup or terminal. I have observed this in foot and more recently ghostty.
I am no expert in terminal control flow and the like, but the issue appears to be a race between the child and parent shell:
child fish: writes ^[]11;? ^[[6n ^[[0c
child fish: fires fish_prompt handlers
devenv hook: PWD is outside the project -> exit
child fish: dies
terminal: replies arrive... nobody is reading
parent fish: resumes, reads pending input, sees ^[]11;rgb:f2f2/... as typed
characters, echoes them onto the command lineThe robot gave me this wonderfully hacky workaround:
function _devenv_hook_exit_on_leave --on-variable PWD
set -q _devenv_hook_dir; or return
test -n "$DEVENV_ROOT"; or return
switch $PWD
case "$DEVENV_ROOT" "$DEVENV_ROOT/*"
case '*'
printf '%s' $PWD >"$DEVENV_ROOT/.devenv/exit-dir"
exit
end
endIt mimics the builtin hook, but executes when there are no outstanding queries:
child fish: runs `cd /tmp`
PWD is assigned -> handler fires -> exit
child fish: dies with nothing pending
parent fish: resumes, reads nothing, draws a clean promptHaving limited firsthand experience with fish hooks, I can't say whether all this is accurate or a particularly good solution, but it does appear to work for me.
To reproduce
devenv hook fish | sourcecdto a devenv → activatecd ..- Observe extra output next to the prompt
Version
devenv 2.3.1 (x86_64-linux)
Source: cachix/devenv