inshellisense: is-zsh not work on my mac

Describe the bug

$ is -s zsh # not work
$ is -s bash # work

Environment

  • OS: [mac arm OSX 13]
  • Output of 0.0.1-rc.10:
  • Nodejs Version: [18.17.3]
  • Shell: [zsh]
  • Shell Version: [5.9]

In my environment, is-zsh is not working properly.

I tried to find the reason, looked at the code, and found:

It is determined by the 6973;PS character to judge prompt start, so inshellintegration-rc.zsh needs to be executed in the zsh environment.

Variable definitions for the folder:

export const userZdotdir = process.env?.ZDOTDIR ?? os.homedir() ?? `~`;
export const zdotdir = path.join(os.tmpdir(), `is-zsh`);

When starting pty, zdotdir will be passed as the value of the environment variable into the new zsh environment.

const convertToPtyEnv = (shell: Shell, underTest: boolean) => {
  const env: Record<string, string> = {
    ...process.env,
    ISTERM: "1",
  };
  if (underTest) env.ISTERM_TESTING = "1";

  switch (shell) {
// ....
    case Shell.Zsh: {
      return { ...env, ZDOTDIR: zdotdir, USER_ZDOTDIR: userZdotdir };
    }
  }
  return env;
};

Here, at startup, the zsh related scripts defined by is are copied to the $temp/is-zsh directory.

export const setupZshDotfiles = async () => {
  const shellFolderPath = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "..", "..", "shell");
  await fsAsync.cp(path.join(shellFolderPath, "shellIntegration-rc.zsh"), path.join(zdotdir, ".zshrc"));
  await fsAsync.cp(path.join(shellFolderPath, "shellIntegration-profile.zsh"), path.join(zdotdir, ".zprofile"));
  await fsAsync.cp(path.join(shellFolderPath, "shellIntegration-env.zsh"), path.join(zdotdir, ".zshenv"));
  await fsAsync.cp(path.join(shellFolderPath, "shellIntegration-login.zsh"), path.join(zdotdir, ".zlogin"));
};

I see the above process is what I expected, but I don’t understand the following code.

In inshellintegration-rc.zsh, if $USER_ZDOTDIR/.zshrc exists, $temp/is-zsh/.zshrc will not be used. In most cases, this file exists, right? So, for most users, is-zsh will not work properly.

if [[ -f $USER_ZDOTDIR/.zshrc ]]; then
	ZDOTDIR=$USER_ZDOTDIR
	. $USER_ZDOTDIR/.zshrc
fi

After I adjusted the code like this, is-zsh can work normally, or running source ./inshellisense/shell/shellIntegration-rc.zsh in is-zsh can also work normally.

if [[ -f $USER_ZDOTDIR/.zshrc ]]; then
---	ZDOTDIR=$USER_ZDOTDIR
	. $USER_ZDOTDIR/.zshrc
fi

In the inshellisense project, I didn’t see related issues, and how to use it in zsh.

So, is it a problem with my environment?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

UPDATE:

The following code was in the bottom of my custom script, moving to the top fixed it. Tell if needed logs anyway.

export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"  # This loads nvm