3 ms·
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 thi
by kstrauser 5y ago
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.
- laumars 5y ago> 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.
- kstrauser 5y agoIn 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.
- stouset 5y agoYou 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.
- forgetfulness 5y agoYour .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.
- laumars 5y agoThe 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.
- forgetfulness 5y agoHow 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 https://github.com/farzadghanei/fishion
- laumars 5y agoWell 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 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.
- faho 5y ago>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.
- digitalsushi 5y agoIt's as simple and seductive as Ruby on Rails was 20 years ago.
- forgetfulness 5y agoI 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_found.html 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.
- faho 5y agoBash 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.html#Command-Execution https://zsh.sourceforge.io/Doc/Release/Command-Execution.htm... for zsh - https://www.gnu.org/software/bash/manual/bash.html#Command-Search-and-Execution 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.