Zsh can't find helix but bash can

Hi all,

I’ve recently started playing around with nixos, working on porting my dots over. Starting with the basics I’ve installed helix editor and started to configure zsh and ohMyZsh etc.

I have helix installed as a systemPackage

My zsh config is in a separate file, under /etc/nixos/zsh/default.nix and for now is a fairly basic setup:

{ pkgs, ... }:

{
  programs.zsh = {
    # enable = true;
    promptInit = "source ${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/powerlevel10k.zsh-theme";
    autosuggestions.enable = true;
    syntaxHighlighting.enable = true;
    shellAliases = {
      rebuild = "sudo nixos-rebuild switch";
    };

    ohMyZsh = {
      enable = true;
      custom = "~/.config/zsh/";
      theme = "gruvbox";
    };
  };
}

So the issue I’m having is that within zsh, if i issue a hx command, i get: helix: command not found

If i switch back to bash the same command opens helix editor as expected.

Interestingly I’ve set SUDO-EDITOR='hx" and in both bash and zsh and as a result I’m able to edit configs using sudoedit

In zsh, my PATH contains a reference to /run/current-system/sw/bin which i believe is where my helix binary is linked to.

If I run ./run/current-system/sw/bin/hx helix opens just fine

I have configured zsh with parts of my configs from my old dotfiles, whilst i wait a reply I’m going to attempt a clean configuration of zsh, ohMyZsh etc with all defaults to rule out any potentially conflicts i may have inadvertently introduces from my old dots.

Thanks!

Maybe shot in the dark, but is oh-my-zsh trying to be cute with aliases by injecting alias hx=helix while the actual binary is literally hx? Check whence hx in zsh

Thanks for the reply,

where hx returned empty, same for where helix

side note: I’ve never heard of whence seems to do the same thing where?

Additional I’ve just ran a clean install with default zsh configs and helix is working as expected. Digging through my configs I found an alias for hx=helix which was carried over from on of my old macbook configs (iirc the helix binary is called helix on osx and hx everywhere else)

Lesson learned, clean configs and track aliases.

Thanks

IIRC whence is a builtin in some shells, but AFAIK type <blah> is a more portable/useful way to answer this question across posixy shells (and type -a <blah>, which is also supported in most cases, is even more useful).

Here’s an example with output from each of the stock shells that shipped on a fairly old macOS:

$ bash -c 'type -a whence git'
bash: line 1: type: whence: not found
git is /run/current-system/sw/bin/git
git is /usr/bin/git

$ csh -c 'type -a whence git'
/usr/bin/type: line 4: type: whence: not found
git is /run/current-system/sw/bin/git
git is /usr/bin/git

(note that type wasn't actually supported in csh here; it fell back on a 'type' from PATH)

$ dash -c 'type -a whence git'
-a: not found
whence: not found
git is /run/current-system/sw/bin/git

$ ksh -c 'type -a whence git'
whence is a shell builtin
git is a tracked alias for /run/current-system/sw/bin/git
git is /usr/bin/git

$ sh -c 'type -a whence git'
sh: line 1: type: whence: not found
git is /run/current-system/sw/bin/git
git is /usr/bin/git

$ tcsh -c 'type -a whence git'
/usr/bin/type: line 4: type: whence: not found
git is /run/current-system/sw/bin/git
git is /usr/bin/git

(note that type wasn't actually supported in tcsh here; it fell back on a 'type' from PATH)

$ zsh -c 'type -a whence git'
whence is a shell builtin
git is /run/current-system/sw/bin/git
git is /usr/bin/git

Edit: not sure if there’s a genuinely ubiquitous POSIX form here. IIRC type is POSIX, so I was a little surprised by the fact that it looks like the csh/tcsh shells here indicate it is running through /usr/bin/type. I don’t know much about tcsh and csh, so I’ll resist falling down that rabbit-hole :slight_smile:

This is explained because csh/tcsh are not POSIX

From Wikipedia

The POSIX standard specifies its standard shell as a strict subset of the Korn shell, an enhanced version of the Bourne shell.

1 Like