withfig / fig

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

Custom prompt prevents autocomplete from working #1163

Closed saifazmi closed 2 years ago

saifazmi commented 2 years ago

Description:

This is a really weird issue. fig does not work on terminal launch, here's the fig doctor output, sorry for all the doctor commands buts its important to explain my findings.

After the third doctor command below, fig starts to work as expected. The difference is that the third fig doctor is being run as sudo and even though the command says that Running doctor as root is not supported. that seems to be inconsequential, as when I go on to run the subsequent command sudo fig doctor --verbose the autocomplete feature starts to work (it will suggest the --verbose flag itself, and I also tested with cd and others)

After a few minutes, again it will stop working, and if you run any sudo fig command, it will start working as expected, and the pattern repeats.

NOTES:

  1. The sequence of the sudo command doesn't matter, i.e. it doesn't need to be the third command.
  2. The command doesn't need to be a doctor command, it can for example be this: sudo fig update and it will have the same behaviour as above. BTW the output of the update command is: Unable to Connect to Fig: Fig might not be running to launch Fig run: fig launch
  3. Clearning the screen ($ clear or Ctrl + L) also seems to make fig stop working

After typing all of this I also discovered that maybe sudo doesn't even matter, because a command like this dasda fig upadsada (yes the typo is on purpose) also results in the same behaviour as described above.

┌─╼[~]
└────╼ fig doctor

✘ Daemon: Daemon socket does not exist
Attempting to fix automatically...
Re-running check...

✘ Daemon: Daemon socket does not exist

✘ Doctor found errors. Please fix them and try again.

If you are not sure how to fix it, please open an issue with fig issue to let us know!
Or, email us at hello@fig.io!
┌─╼[~]
└────╼ fig doctor --verbose
Let's check if you're logged in...
✔ Logged into Fig

Let's check your dotfiles...
✔ .bashrc contains valid fig hooks
✔ .profile contains valid fig hooks
✔ .zshrc contains valid fig hooks
✔ .zprofile contains valid fig hooks

Let's make sure Fig is running...
✔ Fig bin exists
✔ PATH contains ~/.local/bin and ~/.fig/bin
✔ Fig is running
✔ Fig socket exists
✘ Daemon: Daemon socket does not exist
✔ Figterm socket
✔ Insertion lock does not exist
✔ PATH and PseudoTerminal PATH match

Let's check if your system is compatible...
✔ OS is supported

Let's check fig diagnostic...
✔ Installation script
✔ Compatible shell
✔ Fig app installed in the right place
✔ Autocomplete is enabled
✔ Fig CLI path
✔ Accessibility enabled
✔ Secure keyboard input disabled

Let's check your terminal integrations...
✔ iTerm integration is enabled
● VSCode extension is missing!

Fig still not working? Run fig issue to let us know!
Or, email us at hello@fig.io!
┌─╼[~]
└────╼ sudo fig doctor
Password:
Running doctor as root is not supported.
If you know what you're doing, run the command again with --verbose.
sudo fig doctor --verbose
Running doctor as root is not supported.
Let's check if you're logged in...
✔ Logged into Fig

Let's check your dotfiles...
✔ .bashrc contains valid fig hooks
✔ .profile contains valid fig hooks
✔ .zshrc contains valid fig hooks
✔ .zprofile contains valid fig hooks

Let's make sure Fig is running...
✔ Fig bin exists
✔ PATH contains ~/.local/bin and ~/.fig/bin
✔ Fig is running
✘ Fig socket exists: No file at path /var/tmp/fig/root/fig.socket
✘ Daemon: Daemon is not running
  Init system: Launchd
✘ Figterm socket: No TERM_SESSION_ID
✔ Insertion lock does not exist
✔ PATH and PseudoTerminal PATH match

Let's check if your system is compatible...
✔ OS is supported

Let's check fig diagnostic...
Failed to get context: Failed to connect to "/var/tmp/fig/root/fig.socket": No such file or directory (os error 2)

✘ Doctor found errors. Please fix them and try again.

If you are not sure how to fix it, please open an issue with fig issue to let us know!
Or, email us at hello@fig.io!

Details:

OS Fig Shell
macOS 12.3.0 (21E230) 1.0.56 /bin/zsh
fig diagnostic

# Fig Diagnostics ## Fig details: - Fig version: Version 1.0.56 (B416) [U.S.] - Bundle path: /Applications/Fig.app - Autocomplete: true - Settings.json: true - Accessibility: true - Number of specs: 0 - Symlinked dotfiles: false - Only insert on tab: false - Keybindings path: - Installation Script: true - PseudoTerminal Path: /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/saif/.local/bin:/Users/saif/.fig/bin:/Users/saif/.local/bin:/Users/saif/.local/bin - SecureKeyboardInput: false - SecureKeyboardProcess: ## Hardware Info: - Model Name: Mac mini - Model Identifier: Macmini9,1 - Chip: Apple M1 - Cores: 8 (4 performance and 4 efficiency) - Memory: 16 GB ## OS Info: - macOS 12.3.0 (21E230) ## Environment: - User Shell: /bin/zsh - Current Directory: /Users/saif - CLI Installed: true - Executable Location: /Users/saif/.local/bin/fig - Current Window ID: 17953/% (com.googlecode.iterm2) - Active Process: zsh (65407) - /dev/ttys001 - Environment Variables: - TERM_SESSION_ID=w0t0p0:6B674CE3-AE99-4D91-AB2D-194EE18D2396 - PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/saif/.local/bin:/Users/saif/.fig/bin:/Users/saif/.local/bin:/Users/saif/.local/bin - TERM=xterm-256color - FIG_INTEGRATION_VERSION=8 - FIG_TERM=1 - FIG_TERM_VERSION=4.3.0 ## Integrations: - SSH: false - TMUX: false - iTerm: installed! - Hyper: application is not present. - Visual Studio Code: Extension is not installed. - Docker: false

mschrage commented 2 years ago

Hey @saifazmi! Thanks for the detailed bug report.

Can you run the follow commands?

Finally, is the Fig app running? (Do you see the Fig icon in the menubar)

I think you might need to run sudo rm -rf /var/tmp/fig. It looks Fig was launched as root(?) and created a folder in /var/tmp/ that it cannot edit when launched normally.

saifazmi commented 2 years ago

@mschrage here are the outputs of the commands.

┌─╼[~]
└────╼ ls -l@ ~/Library/LaunchAgents/
total 64
...
-rw-r--r--  1 saif  staff  1005 23 Mar 21:06 io.fig.dotfiles-daemon.plist
-rw-r--r--  1 saif  staff   350 23 Mar 20:51 io.fig.launcher.plist
-rw-r--r--  1 saif  staff   510 23 Mar 20:51 io.fig.uninstall.plist
┌─╼[~]
└────╼ ls -l@ /var/tmp/fig/root/fig.socket
ls: /var/tmp/fig/root/fig.socket: No such file or directory
┌─╼[~]
└╼  ls -l@ /var/tmp/fig
total 0
drwxr-xr-x  3 saif  wheel  96 23 Mar 21:04 saif
┌─╼[~]
└────╼ fig diagnostic
# Fig Diagnostics
## Fig details:
  - Fig version: Version 1.0.56 (B416) [U.S.]
  - Bundle path: /Applications/Fig.app
  - Autocomplete: true
  - Settings.json: true
  - Accessibility: true
  - Number of specs: 0
  - Symlinked dotfiles: false
  - Only insert on tab: false
  - Keybindings path:
  - Installation Script: true
  - PseudoTerminal Path: /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/saif/.local/bin:/Users/saif/.fig/bin:/Users/saif/.local/bin:/Users/saif/.local/bin
  - SecureKeyboardInput: false
  - SecureKeyboardProcess: <none>
## Hardware Info:
  - Model Name: Mac mini
  - Model Identifier: Macmini9,1
  - Chip: Apple M1
  - Cores: 8 (4 performance and 4 efficiency)
  - Memory: 16 GB
## OS Info:
  - macOS 12.3.0 (21E230)
## Environment:
  - User Shell: /bin/zsh
  - Current Directory: /Users/saif
  - CLI Installed: true
  - Executable Location: /Users/saif/.local/bin/fig
  - Current Window ID: 17953/% (com.googlecode.iterm2)
  - Active Process: zsh (65407) - /dev/ttys001
  - Environment Variables:
    - TERM_SESSION_ID=w0t0p0:6B674CE3-AE99-4D91-AB2D-194EE18D2396
    - PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/saif/.local/bin:/Users/saif/.fig/bin:/Users/saif/.local/bin:/Users/saif/.local/bin
    - TERM=xterm-256color
    - FIG_INTEGRATION_VERSION=8
    - FIG_TERM=1
    - FIG_TERM_VERSION=4.3.0
## Integrations:
  - SSH: false
  - TMUX: false
  - iTerm: installed!
  - Hyper: application is not present.
  - Visual Studio Code: Extension is not installed.
  - Docker: false

Yes the fig app is running, see the following screenshot: Screenshot 2022-03-23 at 22 24 18

From the output of ls -l@ /var/tmp/fig it doesn't look like the file is owned by root. If anything it seems to be owned by the right user:

┌─╼[~]
└────╼ ls -l@ /var/tmp/fig/saif/fig.socket
srwxr-xr-x  1 saif  wheel  0 23 Mar 21:04 /var/tmp/fig/saif/fig.socket
mschrage commented 2 years ago

Can you type "git com" and then take another screenshot of the debugger?

Does autocomplete appear for you?

saifazmi commented 2 years ago

I do not see the autocomplete: Screenshot 2022-03-23 at 22 44 35

And here's the proof of the behaviour I described in my initial post, I have purposefully used the gibberish command to highlight that sudo has no impact on the issue/behaviour. The pattern seems be that there needs to be anything before the fig command. Screenshot 2022-03-23 at 22 45 48

mschrage commented 2 years ago

This seems like a different issue from the daemon socket not existing.

It seems like your custom prompt may be confusing Fig. Can you share your zshrc/zprofile?

Also try commenting out all non-Fig configuration from your zshrc and see if that resolves the issue? (This will help us isolate where the problem is coming from).

mschrage commented 2 years ago

Hey @saifazmi just want to follow up here. I think the underlying issue is that Fig is not able to determine the text you've typed in the terminal because of the prompt you have configured.

I'd love to get this fixed! If you can share more details about which prompt you are using that would be very helpful! :)

saifazmi commented 2 years ago

Hey @mschrage I'm using:

mschrage commented 2 years ago

Can you try switching to the default “robbyrussell" theme and see if that resolves the issue? (This will narrow down the bug to something related to your theme)

saifazmi commented 2 years ago

Can confirm that the default theme works fine with fig

mschrage commented 2 years ago

I think that the issue may have to do with the %~% sequence here: https://github.com/saifazmi/dotfiles/blob/2c500b72551da5322f651991fdc8c58855a2e6d0/.oh-my-zsh/themes/classyTouch.zsh-theme#L5

I think it should be replaced with %~ as it doesn't seem like %~% is a valid prompt expansion.

https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html

saifazmi commented 2 years ago

Previous version:

local current_dir='%{$fg[red]%}[%{$reset_color%}%~% %{$fg[red]%}]%{$reset_color%}'

Updated it to the following two variations and still doesn't work:

local current_dir='%{$fg[red]%}[%{$reset_color%}%~%{$fg[red]%}]%{$reset_color%}'
local current_dir='%{$fg[red]%}[%{$reset_color%}%~ %{$fg[red]%}]%{$reset_color%}'
sullivan-sean commented 2 years ago

I investigated this a little more. On my machine I'm able to reproduce the issue and it seems like fig will correctly pop up with suggestions after a failed command that exits with nonzero status code. The easiest way to test this was to run false, and on the next line suggestions are correct. If you run true, however, the suggestions will be incorrect.

It seems like the prompt uses conditional prompt expansion of the form %(x.true-text.false-text) and for some reason the true-text is breaking fig. What is weird is that if I set the prompt to just the true-text Fig works just fine.

If you don't mind having the same prompt for when commands exit successfully vs not then one fix would be to just update the prompt to be just the true-text or false-text.

This is definitely a bug on our end though and I will continue to look into it

github-actions[bot] commented 2 years ago

This issue has been automatically closed because there has been no activity for 14 days.