Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Now, create an autoloaded function in Zsh or Bash without looking at a man page.

For zsh:

- Make a file named ~/.config/zsh/functions/foo

- Inside it, define the body of the function for foo

- Add ~/.config/zsh/functions/foo to $fpath with "fpath+=~/.config/zsh/functions"

- Declare foo with "autoload -Uz foo"

> Want to make a function to dynamically set your shell's prompt? Create a function named "fish_prompt" in the file ~/.config/fish/functions/fish_prompt.fish. Ta-da - turns out it doesn't have to be a pain in the neck to do that.

To do the same in zsh:

- define a function (can be autoloaded or not) named prompt_foo_setup to change your prompt

- add the following to your zshrc: "autoload -Uz promptinit; promptinit"

Now you can easily change to your custom "foo" prompt by running "prompt foo".

There are many valid points which make zsh (or bash) hard to use out of the box, but neither of the points you've raised are one of them. One can easily do both without "looking at the man page."



That's what I'm talking about. I'm super comfortable reading the man pages for things, but if a tool wants to take over all the boilerplate and do things for me, awesome! Sure, I can add a function by editing rc files. That doesn't scare me one bit. But... why? There's a lot to be said for convention over configuration.

For context, for a while I was the FreeBSD port maintainer for shells/bash-completion. I'm (too) familiar with the plumbing of various shells. I can do all the manual work myself, but there are lots of things I'd rather be doing instead.


> One can easily do both without "looking at the man page."

How do you know which flags to autoload to use without reading the docs? How did you know to call autoload?


Oh please. The exact same thing can be said for fish. How did the parent commenter know to create a file named ~/.config/fish/functions/foo.fish? How did the parent commenter know to define a function inside that file?

The point is, it's trivial to create an autoloaded function in both fish and zsh. You don't have to look at the man page each time, which is what was being implied in the comment I was responding to.

But to answer your question, you never need to call autoload with flags other than "-Uz" 99.99% of the time. So the idea that you have to consult the manual each time to figure out the flags is plainly not true. As for the fact that you have to call autoload to bring autoloaded functions into scope, what else did you expect? Fish's behavior of bringing undeclared functions into scope isn't exactly intuitive either.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: