jamesob / desk

A lightweight workspace manager for the shell
MIT License
2.54k stars 111 forks source link

Use of `sh -i` in desk run causes process suspension in pipelines #86

Open groner opened 5 years ago

groner commented 5 years ago

This makes desk unusable in some pipelines (or any pipelines if you don't like guessing).

This is a little complicated to reproduce. For instance, changing the first command from ls to seq 10 usually succeeds. I'm not sure what the reason is here, but it is likely related to the fact that seq can produce output sooner than ls.

:; desk run hello ls | desk run hello tac
[hangs]^C
[1]+  Stopped                 desk run hello ls | desk run hello tac
:; fg
desk run hello ls | desk run hello tac
[exits]

Or, if run with no controlling tty, we get warnings but the pipeline is otherwise functional.

:; desk run hello ls | desk run hello tac
bash: cannot set terminal process group (6214): Inappropriate ioctl for device
bash: no job control in this shell
bash: cannot set terminal process group (6211): Inappropriate ioctl for device
bash: no job control in this shell
[correct output follows]

I think this all has something to do with multiple shells trying to manage the foreground process on the terminal. This can be avoided if desk run stops using the -i flag and simply injects . $DESK_ENV; in front of the command to run.

groner commented 5 years ago

The following patch addresses this, but it breaks the alias test.

--- desk
+++ desk
@@ -141,9 +141,9 @@ cmd_go() {
 cmd_run() {
     local TODESK="$1"
     shift;
     if [ $# -eq 1 ]; then
-        cmd_go "$TODESK" -ic "$1"
+        cmd_go "$TODESK" -c ". \$DESK_ENV; $1"
     else
-        cmd_go "$TODESK" -ic '"$@"' -- "$@"
+        cmd_go "$TODESK" -c '. $DESK_ENV; "$@"' -- "$@"
     fi
 }
groner commented 5 years ago

One way to make aliases work would be to use the load code in #80, and couple it with a shell function that handles run in a subshell (using parens, not $SHELL -c).

I guess this could still probably break somebody's workflow somewhere. Not hard to fix, but maybe not fun to trip over.