You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fish really needs more builtins. The two that I'm interested in right now are printf and seq. I have a function in bash that prints out the full 256-color table, using for (( g = 0; g < 6; g++ )) syntax for looping and printf for actually printing each color. time reports this function as taking 0.01 seconds.
The equivalent in Fish requires using seq for loop iteration and either using printf for convenience or using echo for a more awkward command-line that's built in. I'm actually not sure how to even time this since time itself isn't a builtin (but in bash it is). If I time the invocation fish -c rainbow256 (using printf), it takes 1.44s. time fish -c 'echo hi' takes only 0.17s so the rainbow256 function probably takes 1.27s. This is a far cry from the 0.01s that bash took. Modifying the function to use echo instead of printf takes 1.12s overall (0.95s adjusted). And removing the seq (by hardcoding its return value) drops this down to 1.02s (0.85s adjusted).
Overall, the lack of these two builtins (seq and printf) accounted for 0.42s running time, which is almost 30% of the overall time. I imagine most of the remaining time is due to the last non-builtin I'm using, which is math. Bash has builtin math functionality via ((, but Fish relies on a wrapper for bc.
I would like add my vote for a builtin printf. In Bash (an Zsh) I used it extensively for all my pretty-prompt printing needs. After switching to Fish a few days ago, I noticed my prompt becoming somewhat slow, even after converting all my bash/sh scripts to pure fish scripts.
Turns out, I should ease up on the printf and use echo instead. A pity, because I much prefer the printf syntax.
I am aware of this philosophy, and I fully agree with it. However, I also believe there is a fine line between "Lean and mean" and "Simple and slow".
Fish is by no means simple, and as you pointed out, all the tools are still available as external commands. However, I do believe it should be possible to debate which builtin tools would improve performance for the majority of users without incurring any other overhead/penalties.
For me, printf (and to lesser extend seq and math) would be a nice addition as builtin commands, but I also understand the reasons for not having it builtin (yet).
This ticket is a bit abstract. We already have printf so at this point the only concrete suggestion is a builtin for seq, although since seq behaves differently in BSD vs GNU, adding a builtin for it is not necessarily correct (because the builtin would deviate from platform behavior on at least one platform).
I'm going to close this out in favor of filing more targeted tickets on specific desired builtins.
Activity
ridiculousfish commentedon Jul 9, 2012
seq is annoying because it has different behavior on BSD and OS X than it does on Linux (in particular the behavior of seq 0)
JeanMertz commentedon Nov 25, 2012
I would like add my vote for a builtin
printf. In Bash (an Zsh) I used it extensively for all my pretty-prompt printing needs. After switching to Fish a few days ago, I noticed my prompt becoming somewhat slow, even after converting all mybash/shscripts to pure fish scripts.Turns out, I should ease up on the
printfand useechoinstead. A pity, because I much prefer theprintfsyntax.siteshwar commentedon Nov 25, 2012
Design philosophy of fish is to add builtins only when they can't be avoided (See Examples in "The law of minimalism" section here : http://ridiculousfish.com/shell/user_doc/html/design.html ). Still we made echo a builtin to make prompts faster, I am not sure we should do same for printf.
JeanMertz commentedon Nov 25, 2012
I am aware of this philosophy, and I fully agree with it. However, I also believe there is a fine line between "Lean and mean" and "Simple and slow".
Fish is by no means simple, and as you pointed out, all the tools are still available as external commands. However, I do believe it should be possible to debate which builtin tools would improve performance for the majority of users without incurring any other overhead/penalties.
For me,
printf(and to lesser extendseqandmath) would be a nice addition as builtin commands, but I also understand the reasons for not having it builtin (yet).ridiculousfish commentedon Nov 25, 2012
printfis a complicated beast. If someone were to provide it as a patch or pull request, I'd take it, as long as it came with a good test suite.If anyone decides to tackle this, IEEE Std 1003.1 will be your friend.
siteshwar commentedon Mar 22, 2013
@JeanMertz printf has been added as builtin in fish with 3830c0a
lilyball commentedon Oct 29, 2014
This ticket is a bit abstract. We already have
printfso at this point the only concrete suggestion is a builtin forseq, although sinceseqbehaves differently in BSD vs GNU, adding a builtin for it is not necessarily correct (because the builtin would deviate from platform behavior on at least one platform).I'm going to close this out in favor of filing more targeted tickets on specific desired builtins.