figを入れたのにコマンドが補完されない

## 概要

- brewを使ってfigをインストールした。アクセシビリティ系の権限許可なども行いVScodeのターミナルで動作確認したがコマンドがサジェストされないので解決までの道のりを記載する。

## 問題発生までの経緯

- 下記コマンドを実行してfigをインストールした。

    ```
    brew install fig
    ```

- インストール後に表示されるfigのウインドウの指示に従って各種設定を行った。
- メールアドレスの認証やログインも行った。

## 問題

- コマンドが補完されずサジェストタブが表示されない。

## 問題解決までの経緯

1. 下記コマンドを実行して解析を試みた。

    ```shell
    fig doctor
    ```

1. 下記のエラーが出た。

    ```shell
    PATH contains ~/.local/bin: Path does not contain ~/.local/bin


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

1. 直訳

    ```shell
    PATH に ~/.local/bin が含まれています: パスに ~/.local/bin が含まれていません

    ✘ 医師がエラーを発見しました。 それらを修正して、もう一度お試しください。
    ```

1. 必要なものがないっぽい。
1. エラーで検索したら下記のissueがヒットした。
    1. [https://github.com/withfig/fig/issues/1370](https://github.com/withfig/fig/issues/1370)
1. 下記コマンドを実行するとレポートが詳しく出るらしいので実行してみる。

    ```shell
    fig doctor --verbose
    ```

1. 下記のように出力された。

    ```shell
   $ fig doctor --verbose
   Let's check if you're logged in...
   ✔ Logged into Fig
   
   Let's check your dotfiles...
   ✔ bash ~/.bashrc integration check
   ✔ bash ~/.bash_profile integration check
   ● /Users/shun/.zshrc does not source pre integration
   ● /Users/shun/.zprofile does not source pre integration
   
   Let's make sure Fig is setup correctly...
   ✔ Fig bin exists
   ✘ PATH contains ~/.local/bin: Path does not contain ~/.local/bin
   ✘ PATH contains ~/.fig/bin: Path does not contain ~/.fig/bin
   ✔ Settings Corruption
   ✔ State Corruption
   ✘ Fig Integration: Figterm is not running in this terminal, please try restarting your terminal
   
     FIG_TERM=
   ✘ SSH integration: Integration not installed: /Users/shun/.ssh/config does not exist.
   
      0: Integration not installed: /Users/shun/.ssh/config does not exist.
   
   Location:
      fig_cli/src/cli/doctor.rs:1244
   
   Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
   Run with RUST_BACKTRACE=full to include source snippets.
   
   Let's make sure Fig is running...
   ✔ Fig is running
   ✔ Fig socket exists
   ✔ Daemon
   ✔ Daemon diagnostics
   
   Let's see if Fig is in a working state...
   ✘ Figterm: No FIGTERM_SESSION_ID
   
      0: No FIGTERM_SESSION_ID
      1: environment variable not found
   
   Location:
      fig_cli/src/cli/doctor.rs:649
   
   Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
   Run with RUST_BACKTRACE=full to include source snippets.
   ✔ Insertion lock does not exist
   ✔ Autocomplete dev mode
   ✔ Plugin dev mode
   ✔ Dashboard is loading from the correct URL
   ✔ Autocomplete is loading from the correct URL
   
   Let's check if your system is compatible...
   ✔ OS is supported
   ✔ Fish is up to date
   ✔ Jetbrains Toolbox Check
   
   Let's check fig diagnostic...
   ✔ Compatible shell
   ✔ Fig app installed in the right place
   ✔ Autocomplete is enabled
   ✔ Fig CLI path
   ✔ Accessibility enabled
   
   Let's check your terminal integrations...
   ✔ Terminal support
   
   
     Fig still not working? Run fig issue to let us know!
     Or, email us at hello@fig.io!
    ```

1. 解決策を書いてくれている人がいた。
    1. [https://github.com/withfig/fig/issues/1370#issuecomment-1219265675](https://github.com/withfig/fig/issues/1370#issuecomment-1219265675)
1. ↑の通りやってみる。（ただしviのほうがなれているのでこちらを使う）

    ```shell
    sudo vi /etc/paths
    ```

1. 開いたファイルの末尾に下記を追記する。

    ```/etc/paths
    /.local/bin
    /.fig/bin
    ```

1. 念の為PCを再起動する。
1. 下記を実行する。

    ```shell
    fig doctor --verbose
    ```

1. ちょっとだけエラーが減った。別の部分も解決する必要がある。

    ```shell
    $ fig doctor --verbose
    Let's check if you're logged in...
    ✔ Logged into Fig
    
    Let's check your dotfiles...
    ✔ bash ~/.bashrc integration check
    ✔ bash ~/.bash_profile integration check
    ● /Users/shun/.zshrc does not source pre integration
    ● /Users/shun/.zprofile does not source pre integration
    
    Let's make sure Fig is setup correctly...
    ✔ Fig bin exists
    ✔ PATH contains ~/.local/bin
    ✔ PATH contains ~/.fig/bin
    ✔ Settings Corruption
    ✔ State Corruption
    ✔ Fig Integration
    ✘ SSH integration: Integration not installed: /Users/shun/.ssh/config does not exist.
    
       0: Integration not installed: /Users/shun/.ssh/config does not exist.
    
    Location:
       fig_cli/src/cli/doctor.rs:1244
    
    Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
    Run with RUST_BACKTRACE=full to include source snippets.
    
    Let's make sure Fig is running...
    ✔ Fig is running
    ✔ Fig socket exists
    ✔ Daemon
    ✔ Daemon diagnostics
    
    Let's see if Fig is in a working state...
    ✔ Figterm
    ✔ Insertion lock does not exist
    ✔ Autocomplete dev mode
    ✔ Plugin dev mode
    ✔ Dashboard is loading from the correct URL
    ✔ Autocomplete is loading from the correct URL
    
    Let's check if your system is compatible...
    ✔ OS is supported
    ✔ Fish is up to date
    ✔ Jetbrains Toolbox Check
    
    Let's check fig diagnostic...
    ✔ Compatible shell
    ✔ Fig app installed in the right place
    ✔ Autocomplete is enabled
    ✔ Fig CLI path
    ✔ Accessibility enabled
    
    Let's check your terminal integrations...
    ✔ Terminal support
    
    
      Fig still not working? Run fig issue to let us know!
      Or, email us at hello@fig.io!
    ```

1. 次に解決すべきエラーは下記である。

    ```shell
    ✘ SSH integration: Integration not installed: /Users/shun/.ssh/config does not exist.
    
       0: Integration not installed: /Users/shun/.ssh/config does not exist.
    
    Location:
       fig_cli/src/cli/doctor.rs:1244
    
    Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
    Run with RUST_BACKTRACE=full to include source snippets.
    ```

1. 直訳

    ```shell
    ✘ SSHの統合を行いました。統合がインストールされていません。/Users/shun/.ssh/config は存在しません。
    
       0: 統合がインストールされていません。/Users/shun/.ssh/config は存在しません。
    
    場所を指定します。
       fig_cli/src/cli/doctor.rs:1244
    
    バックトレースは省略されています。環境変数RUST_BACKTRACE=1を指定して実行すると表示されます。
    RUST_BACKTRACE=fullで実行すると、ソーススニペットが含まれます。
    ```

1. 自身のhomeディレクトリ直下に.sshディレクトリ内にconfigファイルがないらしい。とりあえず/Users/shun/.ssh/直下にからのconfigファイルを設置してみる。

    ```shell
    touch /Users/shun/.ssh/config
    ```

1. 下記を実行する。

    ```shell
    fig doctor --verbose
    ```

1. ちょっとだけエラーが変わった。

    ```shell
    $ fig doctor --verbose
    Let's check if you're logged in...
    ✔ Logged into Fig
    
    Let's check your dotfiles...
    ✔ bash ~/.bashrc integration check
    ✔ bash ~/.bash_profile integration check
    ● /Users/shun/.zshrc does not source pre integration
    ● /Users/shun/.zprofile does not source pre integration
    
    Let's make sure Fig is setup correctly...
    ✔ Fig bin exists
    ✔ PATH contains ~/.local/bin
    ✔ PATH contains ~/.fig/bin
    ✔ Settings Corruption
    ✔ State Corruption
    ✔ Fig Integration
    ✘ SSH integration: /Users/shun/.fig/ssh does not exist.
    
       0: /Users/shun/.fig/ssh does not exist.
    
    Location:
       fig_cli/src/cli/doctor.rs:1244
    
    Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
    Run with RUST_BACKTRACE=full to include source snippets.
    
    Let's make sure Fig is running...
    ✔ Fig is running
    ✔ Fig socket exists
    ✔ Daemon
    ✔ Daemon diagnostics
    
    Let's see if Fig is in a working state...
    ✔ Figterm
    ✔ Insertion lock does not exist
    ✔ Autocomplete dev mode
    ✔ Plugin dev mode
    ✔ Dashboard is loading from the correct URL
    ✔ Autocomplete is loading from the correct URL
    
    Let's check if your system is compatible...
    ✔ OS is supported
    ✔ Fish is up to date
    ✔ Jetbrains Toolbox Check
    
    Let's check fig diagnostic...
    ✔ Compatible shell
    ✔ Fig app installed in the right place
    ✔ Autocomplete is enabled
    ✔ Fig CLI path
    ✔ Accessibility enabled
    
    Let's check your terminal integrations...
    ✔ Terminal support
    
    
      Fig still not working? Run fig issue to let us know!
      Or, email us at hello@fig.io!
    ```

1. /Users/shun/.fig/直下にsshファイルがないらしい。つくてみる。

    ```shell
    touch /Users/shun/.fig/ssh
    ```

1. 下記を実行する。

    ```shell
    fig doctor --verbose
    ```

1. ちょっとだけエラーが変わった。

    ```shell
    $ fig doctor --verbose
    Let's check if you're logged in...
    ✔ Logged into Fig
    
    Let's check your dotfiles...
    ✔ bash ~/.bashrc integration check
    ✔ bash ~/.bash_profile integration check
    ● /Users/shun/.zshrc does not source pre integration
    ● /Users/shun/.zprofile does not source pre integration
    
    Let's make sure Fig is setup correctly...
    ✔ Fig bin exists
    ✔ PATH contains ~/.local/bin
    ✔ PATH contains ~/.fig/bin
    ✔ Settings Corruption
    ✔ State Corruption
    ✔ Fig Integration
    ✘ SSH integration: Improper integration installation: /Users/shun/.fig/ssh should contain:
    Match exec="command -v fig && fig _ generate-ssh %r"
      Include ~/.fig/ssh_inner
    
    
       0: Improper integration installation: /Users/shun/.fig/ssh should contain:
          Match exec="command -v fig && fig _ generate-ssh %r"
            Include ~/.fig/ssh_inner
       0: 
    
    Location:
       fig_cli/src/cli/doctor.rs:1244
    
    Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
    Run with RUST_BACKTRACE=full to include source snippets.
    
    Let's make sure Fig is running...
    ✔ Fig is running
    ✔ Fig socket exists
    ✔ Daemon
    ✔ Daemon diagnostics
    
    Let's see if Fig is in a working state...
    ✔ Figterm
    ✔ Insertion lock does not exist
    ✔ Autocomplete dev mode
    ✔ Plugin dev mode
    ✔ Dashboard is loading from the correct URL
    ✔ Autocomplete is loading from the correct URL
    
    Let's check if your system is compatible...
    ✔ OS is supported
    ✔ Fish is up to date
    ✔ Jetbrains Toolbox Check
    
    Let's check fig diagnostic...
    ✔ Compatible shell
    ✔ Fig app installed in the right place
    ✔ Autocomplete is enabled
    ✔ Fig CLI path
    ✔ Accessibility enabled
    
    Let's check your terminal integrations...
    ✔ Terminal support
    
    
      Fig still not working? Run fig issue to let us know!
      Or, email us at hello@fig.io!
    ```

1. うまく統合インストールできてない的なエラーが出ている。

    ```shell
    ✘ SSH integration: Improper integration installation: /Users/shun/.fig/ssh should contain:
    Match exec="command -v fig && fig _ generate-ssh %r"
      Include ~/.fig/ssh_inner
    
    
       0: Improper integration installation: /Users/shun/.fig/ssh should contain:
          Match exec="command -v fig && fig _ generate-ssh %r"
            Include ~/.fig/ssh_inner
    ```

1. 直訳

    ```shell
    ✘ SSHの統合。統合のインストールが適切でない。/Users/shun/.fig/ssh が含まれている必要があります。
    マッチ exec="command -v fig && fig _ generate-ssh %r"
      インクルード ~/.fig/ssh_inner
    
    
       0：不適切な統合インストールです。/Users/shun/.fig/ssh が含まれている必要があります。
          マッチ exec="command -v fig && fig _ generate-ssh %r"
            インクルード ~/.fig/ssh_inner
    ```

1. 近いことで困っている方がいた。
    1. [https://github.com/withfig/fig/issues/2148#issuecomment-1352350670](https://github.com/withfig/fig/issues/2148#issuecomment-1352350670)
1. 下記コマンドを実行してみる。

    ```shell
    fig integrations install ssh
    ```

1. 下記のように帰ってきた

    ```
    $ fig integrations install ssh
    Installed!
    ```

1. 下記を実行する。

    ```shell
    fig doctor --verbose
    ```

1. 問題は解決した模様

    ```shell
    $ fig doctor --verbose
    Let's check if you're logged in...
    ✔ Logged into Fig
    
    Let's check your dotfiles...
    ✔ bash ~/.bashrc integration check
    ✔ bash ~/.bash_profile integration check
    ● /Users/shun/.zshrc does not source pre integration
    ● /Users/shun/.zprofile does not source pre integration
    
    Let's make sure Fig is setup correctly...
    ✔ Fig bin exists
    ✔ PATH contains ~/.local/bin
    ✔ PATH contains ~/.fig/bin
    ✔ Settings Corruption
    ✔ State Corruption
    ✔ Fig Integration
    ✔ SSH integration
    
    Let's make sure Fig is running...
    ✔ Fig is running
    ✔ Fig socket exists
    ✔ Daemon
    ✔ Daemon diagnostics
    
    Let's see if Fig is in a working state...
    ✔ Figterm
    ✔ Insertion lock does not exist
    ✔ Autocomplete dev mode
    ✔ Plugin dev mode
    ✔ Dashboard is loading from the correct URL
    ✔ Autocomplete is loading from the correct URL
    
    Let's check if your system is compatible...
    ✔ OS is supported
    ✔ Fish is up to date
    ✔ Jetbrains Toolbox Check
    
    Let's check fig diagnostic...
    ✔ Compatible shell
    ✔ Fig app installed in the right place
    ✔ Autocomplete is enabled
    ✔ Fig CLI path
    ✔ Accessibility enabled
    
    Let's check your terminal integrations...
    ✔ Terminal support
    
    
      Fig still not working? Run fig issue to let us know!
      Or, email us at hello@fig.io!
    ```

1. doctorコマンドのオプションなしも実行しておく。

    ```shell
    $ fig doctor
    
    ● /Users/shun/.zshrc does not source pre integration
    ● /Users/shun/.zprofile does not source pre integration
    
    ✔ Everything looks good!
    
      Fig still not working? Run fig issue to let us know!
      Or, email us at hello@fig.io!
    ```

1. 問題なさそう。一旦Macそのものを再起動してみる。
1. Vscodeのターミナルを使って補完を確認してみたところ正常に補完された。

    ![スクリーンショット_2023-03-18_10_59_08.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/306417/8778d10b-0666-723a-cf7c-184af8061648.png)

1. 問題解決

## 2024/04/11 追記

その後またfigの動作が怪しくなったので「Amazon CodeWhisperer」に乗り換えた↓

https://qiita.com/miriwo/items/319a4932c190bacd1bac

## 参考文献

https://fig.io/user-manual/install