withfig / fig

Public issue tracker for Fig.
https://fig.io
MIT License
2.06k stars 63 forks source link

Text entered too quickly on shell startup isn't sent to shell #446

Closed fwesss closed 2 years ago

fwesss commented 3 years ago

Sanity checks

Issue Details

Description:

I have tasks setup in VSCode to run on keyboard shortcuts. When Fig is installed, triggering the task drops me into a terminal prompt but the task does not run.

image

Environment

N/A
mschrage commented 2 years ago

Before installing: https://user-images.githubusercontent.com/3155109/148602019-19239571-5e34-4d88-a76d-c65923b2dac0.mov

After installing: https://user-images.githubusercontent.com/3155109/148602015-392538a2-f5ca-4f5d-a407-4059d13d7d49.mov

sullivan-sean commented 2 years ago

Having a hard time reproducing this in the most recent version

https://user-images.githubusercontent.com/22581534/149391518-e62c0e1c-8f3b-4c64-9532-07d23e3ba87f.mov

clo4 commented 2 years ago

I can reproduce this with withfig/autocomplete, haven't tried elsewhere.

https://user-images.githubusercontent.com/52195359/154195986-ebdc5428-70d5-4944-b7a3-2dccb58c2cff.mp4

(autocomplete not showing because 1Password triggering secure input)

clo4 commented 2 years ago

Same thing happens using a raycast shell script.

https://user-images.githubusercontent.com/52195359/154207756-852c117c-39c9-46c7-a363-2faf57edb29b.mp4

brendanfalk commented 2 years ago

@tyriar - perhaps you could help here.

How exactly does VSCode tasks send code to the terminal? Is it pasted in at the OS/xterm level or done through the shell?

What's happening is your shell session loads, then immediately after, Fig's pseuodterminal, figterm, is loading. The time difference there is tiny and effectively not noticeable if the user is typing. But it seems like automated processes like VSCode tasks have their text eaten up somehow.

How can we help users get around this? Ideas:

  1. Set env variable that is the text to be pasted and then we can copy it in later.
  2. Add a delay before inserting.

Any thoughts for us?

Thanks for you time!

Tyriar commented 2 years ago

You can see exactly how the shell gets launched by setting log level to trace via the command palette and checking the devtools console. Here's an example of a task running on macOS:

Screen Shot 2022-02-22 at 7 10 12 am

So it's essentially bash -c <command> here. Is the problem that you're sourcing fig in non-interactive terminals? Fig shouldn't be running at all for tasks imo. Note also that the VS Code "shell environment" that belongs to the window is sourced by running env in an $SHELL -ilc, terminal processed inherit this environment by default so variables that fig exports could show up in the environment that the task shell is launched with.

I don't know what you could be doing to cause what's happening in the recordings other than launching a sub shell which you definitely shouldn't be doing in a task as it would break everything.

brendanfalk commented 2 years ago

@sullivan-sean @SeparateRecords

  1. turn figterm off for non-interactive shells
  2. add a check to fig doctor that tells users if they are in a non-interactive shell that they are running interactively
mschrage commented 2 years ago

Note: when bash and zsh include a -c flag, they set a shell variable that corresponds to it: BASH_EXECUTION_STRING and ZSH_EXECUTION_STRING respectively.

We can read this value and use it to set FIG_INITIAL_TEXT.

Or we can just launch the figterm's child shell with the same arguments.

brendanfalk commented 2 years ago

This issue also occurs with https://github.com/mklement0/ttab

mschrage commented 2 years ago

@SeparateRecords I can't seem to reproduce this.

I can reproduce this with withfig/autocomplete, haven't tried elsewhere.

CleanShot.2022-02-16.at.15.22.44.mp4 (autocomplete not showing because 1Password triggering secure input)

clo4 commented 2 years ago

@mschrage Weird, this is super reliably reproducible for me - maybe a fish thing? Although a lot of people seem to have this bug with zsh too. You're welcome to remote into my machine to debug stuff.

mschrage commented 2 years ago

Narrator: it was a fish thing.

This should be resolved in the next release. In bash/zsh, Fig detects if a shell has been launched with -c. In fish, Fig is not attached to non-interactive shells.