News for hackers. Stuff that matters.
Re:s/bash/zsh/g by kstrauser on Wednesday October 20, 2021 @02:29PM (#28934210)
Don't think of it as magic, but as convention. Where do you put your function definitions? In the folder named "functions". There are only a handful of such things to learn.
Re:s/bash/zsh/g by laumars on Wednesday October 20, 2021 @02:33PM (#28934285)
> Where do you put your function definitions?

Inside ‘function’ blocks, like the language syntax defines for any other type of function. I can then throw those functions into any file I chose.

Having special functions inside special files just creates annoying special cases I need to look up.

Re:s/bash/zsh/g by kstrauser on Wednesday October 20, 2021 @02:38PM (#28934371)
In fish, you put the functions inside function blocks. There's nothing at all magical about that. However, if you write "function foo" inside a file named "foo.fish", then type the command "foo" at the shell prompt, then fish will look for a file named "foo.fish" and then execute the function "foo" defined inside it. That's its autoload mechanism.

That's the only remotely magical thing added here: by convention, an autoload function named "foo" is defined in ~/.config/fish/functions/foo.fish.

Re:s/bash/zsh/g by forgetfulness on Wednesday October 20, 2021 @04:11PM (#28935764)
Your .bashrc, .zshrc, .profile, etc. files are also special. All that's going on is that there is folder where you can leave functions to be included in the main namespace, I don't see the big difference.
Re:s/bash/zsh/g by laumars on Wednesday October 20, 2021 @07:17PM (#28938117)
The difference as I understand it is your Fish equivalent of a $PS1 (and other Fish shell behaviours) have to be defined via that path. If I understand it correctly, it sounds a lot like git hooks but at a global scale rather than per repo.

Now I’ve got nothing against git hooks nor Fish per se, I just don’t see this particular model for defining behaviour to be convenient (eg what if you want to quickly change the prompt of a session without affecting other sessions?)

There might be more detail I’m missing and if that’s the case I apologise. But from what I’ve read thus far I’m not sold. It might appeal to others and good for them.

Re:s/bash/zsh/g by forgetfulness on Wednesday October 20, 2021 @11:35PM (#28939907)
How would you normally do it? Because you can still put redefinitions of all the standard functions into a single file and load them with `.` as you would with other shells.

There's also this package, which the author admits only allows "slight" customization, to implement sessions: https://github.com/farzadghanei/fishion

Re:s/bash/zsh/g by laumars on Thursday October 21, 2021 @02:20AM (#28941017)
Well I’m not suggesting the following is a better alt shell, but in murex you have something that’s a little bit akin to a Windows Registry in that all of the shell settings are navigable through a builtin called ‘config’

https://murex.rocks/docs/commands/config.html

You can set prompt functions with that; strings, ints and Booleans too. And ‘config’ comes with descriptions for each configurable thing, choices of options in many cases, and an easy way to default back to shell defaults too. So it’s dead easy to play around configuring whatever you want (you never need to leave the shell to look up an option).

The shell has its own problems though but it’s an interesting alternative take for grouping shell config.

Re:s/bash/zsh/g by faho on Thursday October 21, 2021 @03:10AM (#28941332)
>The difference as I understand it is your Fish equivalent of a $PS1 (and other Fish shell behaviours) have to be defined via that path.

They don't. You have to define the function somehow, but fish doesn't care about how that happens. It's just that if it's not defined yet it'll try to load it from the file.

If you want, you can just do it all in config.fish, like you'd do it all in .bashrc for bash.

>what if you want to quickly change the prompt of a session without affecting other sessions?

Then you can redefine the function, just like you could switch the value of $PS1.

Re:s/bash/zsh/g by laumars on Thursday October 21, 2021 @06:22AM (#28942515)
Ok. That sounds a lot more sane then. Thank you for the clarification.
Re:s/bash/zsh/g by stouset on Wednesday October 20, 2021 @02:54PM (#28934591)
You can literally still do it the way you want, there's just a convention that `fish` uses to autoload so you don't have to if you don't want to.
Re:s/bash/zsh/g by digitalsushi on Wednesday October 20, 2021 @04:53PM (#28936413)
It's as simple and seductive as Ruby on Rails was 20 years ago.
Re:s/bash/zsh/g by forgetfulness on Wednesday October 20, 2021 @11:44PM (#28939958)
I was going to mount a defense of fish about how it doesn't provide the same mechanisms or provide the same incentives that had people contorting Ruby into the most convoluted forms on their way to spit out HTML or JSON from an HTTP request, but then I found that the thing has a `fish_command_not_found` that you can overload as in Ruby.

https://fishshell.com/docs/current/cmds/fish_command_not_fou...

So yeah you could make crazy stuff like Rail's routing and rendering DSLs that interpreted method names as programs.

Re:s/bash/zsh/g by faho on Thursday October 21, 2021 @08:42AM (#28943566)
Bash and zsh have basically the same thing.

It's meant to give you a nice error message like

"foo is missing. You can install it with 'apt install foo123'"

See:

- https://zsh.sourceforge.io/Doc/Release/Command-Execution.htm... for zsh

- https://www.gnu.org/software/bash/manual/bash.html#Command-S... for bash

You could make it run arbitrary things, but then you're quite clearly misusing it and e.g. there's no way to make it return a different status, fish will still view the command as failed.