Help passing zsh prompt string using home-manager

Hi,

I’ve got a zsh prompt string I’m trying to pass into the .zshrc file but it’s got a variable in the string which is causing problems. Here is the string;

PROMPT="(%F{magenta}%D{%d/%m/%y %H:%M:%S}%f) %F{cyan}%n%f@%F{cyan}%m%f in %F{2}%~%f %F{red}%#%f ‘’${vcs_info_msg_0_}>> "

I’ve tried putting a ‘‘ infront of the ${ which works but then zsh ignores it because it’s escaped.

Is there any other way to get the string as is through? It’s showing me some git information when I’m in a git directory.

Thanks!

The two single quotes is for “indented strings”; for plain strings put a backslash in front: "\${bar}".

1 Like

Hi,

Thanks for the reply. I tried that as well but I still get;

error: undefined variable ‘vcs_info_msg_0_

PROMPT="(%F{magenta}%D{%d/%m/%y %H:%M:%S}%f) %F{cyan}%n%f@%F{cyan}%m%f in %F{2}%~%f %F{red}%#%f \${vcs_info_msg_0_}>> ‘

Please use triple backticks around codeblocks (and put the triple backticks on their own line without any other code in there). The smart-quoting is confusing and unclear whether that’s due to discourse or what you actually typed in your config.

Thanks for the help, i’ve fixed the code in the post.

1 Like

Thanks, based on that message it seems like you’re actually using an indented string. Does $vcs_info_msg_0_ cause any issues? Could you share the larger code block where this code is located?

Sure thing, this is my home.nix file;

{ config, pkgs, ... }:

{
  home.username = "michael";
  home.homeDirectory = "/home/michael";
  home.stateVersion = "26.05";
  programs.zsh = {
    enable = true;
    shellAliases = {
      rbr = "sudo nixos-rebuild switch --flake .#radar";
    };
    initContent = ''
      autoload -Uz vcs_info
      prevmd() { vcs_info }
      zstyle ':vcs_info:git:*' formats '[%F{yellow}%b%f]'
      setopt PROMPT_SUBST
      PROMPT='(%F{magenta}%D{%d/%m/%y %H:%M:%S}%f) %F{cyan}%n%f@%F{cyan}%m%f in %F{2}%~%f %F{red}%#%f \${vcs_info_msg_0_}>> '
    '';
  };

  programs.vim = {
    enable = true;
    extraConfig = ''
      set number
    '';
  };

}

And this is the error;

      error: undefined variable 'vcs_info_msg_0_'
       at /nix/store/pjj03ql41s7ba761zq04vla3w27sp1a2-source/home/home.nix:17:106:
           16|       setopt PROMPT_SUBST
           17|       PROMPT='(%F{magenta}%D{%d/%m/%y %H:%M:%S}%f) %F{cyan}%n%f@%F{cyan}%m%f in %F{2}%~%f %F{red}%#%f \${vcs_info_msg_0_}>> '
             |                                                                                                          ^
           18|     '';

Somehow trying the same thing for the nth time worked, ‘‘ before the $ did the job. Thanks all!