News for hackers. Stuff that matters.
Re:s/bash/zsh/g by krinchan on Wednesday October 20, 2021 @04:11PM (#28935769)
Setting a specific path as an “autoload” path to load shell functions is in bash and zsh too?
Re:s/bash/zsh/g by laumars on Wednesday October 20, 2021 @07:06PM (#28938016)
Yeah, but there aren’t magic function paths that you need to do basic things like setting the prompt.

Don’t get me wrong, I think the PS1 variable sucks. But I’m not convinced Fish’s solution is much better.

Re:s/bash/zsh/g by krinchan on Thursday October 21, 2021 @01:40PM (#28948107)
Okay so I think I understand your objection a bit more. So fish only wants you to define a function called fish_prompt in order to customize the prompt. That function can be defined however you want. It can be in fish’s equivalent of .bashrc (~/.config/fish/config.fish). Putting it in ~/.config/fish/functions/fish_prompt.fish is just leveraging more tooling around shell function autoloading and sane defaults.

You can achieve PS1-like functionality “simply” by placing this bit of code somewhere in your startup:

  function fish_prompt
      set -l prompt_symbol '$'
      fish_is_root_user; and set prompt_symbol '#'

      echo -s $hostname (set_color blue) (prompt_pwd) \
      (set_color yellow) $prompt_symbol (set_color normal)
  end
It’s very verbose but it runs as fast as both bash’s PS1 and zsh’s PROMPT and is much easier for someone new to fussing with prompts to comprehend.

Even as someone who doesn’t use fish day to day, I think fish’s prompt customization is much more approachable. If I had a powerline prompt I wanted to tweak, I’d know to start with `functions fish_prompt` to print out the current contents of the function and have the complete code to how the prompt is built. zsh requires a lot more reading and understanding of the prompt system before you can dig into how exactly it all works. IIRC, most dynamic bash prompts have similar issues. PS1 is just interpolated globals and color codes, creating a disconnect between the prompt variable and the shell functions that update it.