Live data from Hacker News

Fish shell 3.0

github.com

211–220 of 227 posts

Re: Fish shell 3.0

#211
post #49

Earlier quoted context omitted.

I much prefer fish to zsh + omz. Most of the functionality is built in, and there are plugins for any missing ones (nvm is a big one).

I never got nvm working for me, so after a few years on fish, I switched back to ZSH just for nvm. Any tips on how to get it working? I think it had to do bass not working though, so the plugin didn't work. Now that I'm on NixOS I might give it another shot.

   fisher add FabioAntunes/fish-nvm
worked for me!

https://github.com/FabioAntunes/fish-nvm

Re: Fish shell 3.0

#212
post #144
post #79

Earlier quoted context omitted.

What? That's been in for a few releases! To trigger it, enter a single-quote, then paste the URL, then close the quote once you're done. We don't attempt to detect URLs because that can go wrong, and because we don't know your intention. So we use the fact that you're inside single-quotes as the signifier that we should escape things - which also allows this to be used for e.g. pasting shellscript as a literal argume…

How can detecting URL go wrong? It starts with an obvious prefix and ends at a line end or a space. If the URL contained a space that is not URL encoded, that would be user's fault.

it's not as obvious as it looks. maybe someone wants to construct urls like this:

    wget http://example.com/files/(basename -s .jpg *.jpg).png
but ( is a legal character in urls, so fish can't possibly predict which use is desired.

Re: Fish shell 3.0

#213

Earlier quoted context omitted.

When I’ve been teaching people to program, explaining [0] has been a tragic experience. Starting at [0] is not objectively better than [1]. I actually believe it is objectively worse .

I would like to hear your counterarguments to https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E... , which seems to me like a compelling argument.

Everybody has an intuition of lists or sequences, and the idea of something being “first”, snd that being labeled “1”.

When teaching people to program, portraying the idea of “jumping zero steps” into a list to get the first element has been an inefficient embarassment every single time I’ve been present.

Re. Dijkstra’s argument:

1: Everybody has an intuition of an ends-inclusive “from x to y”. Everyone would include 2 and 12 if asked to “count from 2 to 12”.

2: What’s wrong with using three dots? What is pernicious about them?

3: Labeling and length calculations always require a shift of one. If we make the ends compatible with thought-free length calculation, then sequence labeling is always off. If we have intuitive sequence labeling then we need to adjust either end label by one to get the length. The latter approach is far more intuitive. Also, one should just ask the damn computer what the length is. That’s what it’s for. Pardon the language. Especially as we will always want to leave behind and tend to leave behind the abject simplicity of hand-calculating the length of our data from the labels of the bump stops; Our data structures may not even support that calculation. So why couple ourselves to that calculation and sacrifice the ability to have sequence labels make sense?

And why don’t we just have both? Keep array[0] as first, fine, whatever, and add array|1| as first too.

Re: Fish shell 3.0

#214
post #54

Earlier quoted context omitted.

I also do that, often with loops. for ((i=0;i out-$i.log 2>&1 ) & done Can be anything from image processing, video transcoding, file decompression, file system analysis - anything I think may complete faster with some concurrency.

Something like this should do the same thing, I think?: seq 0 3 | parallel "./ad-hoc-operation > out-{}.log" https://www.gnu.org/software/parallel/

Might do. OTOH I often have a shell pipeline as the body of the loop, rely on glob expansion, etc. For ad-hoc parallelism of a simple command over lots of data, I tend to use xargs -n -P - since I use xargs for other things, I stick with it.

Also, bash and xargs are available everywhere, on production servers as well as dev laptops. Anything that requires installing something has a big hurdle to overcome - this counts for fish too.

Re: Fish shell 3.0

#215

After 15 years, I still struggle to test if a string is empty in shell languages. Do I use square brackets, double square brackets, equal sign, double equal sign, test -n, set -q, wtf mate? Do I need to wrap my string variable in double quotes? single quotes? Fish looks great, and I'm going to give it a try, but I ran into these same old shell scripting issues within 2 minutes of trying to configure my prompt, which…

I don't know, but I just use fish for interactive use and write shell scripts using #!/bin/sh.

Re: Fish shell 3.0

#216

Earlier quoted context omitted.

I run tcsh. It won’t.

You know you run tcsh. fish users usually know they run fish. You don't expect to be able to run arbitrary copy-pasted shell snippets in the first place.

I try to run my scripts on /bin/sh (on a system where that's not just a symlink to a fancier shell) before posting them. That means it's more portable, but still not universal. I don't typically have bash on my BSD systems, and when I do, they're not installed to /bin, so this is also somewhat out of self interest as well.

Re: Fish shell 3.0

#217
post #174

Earlier quoted context omitted.

There's an outstanding issue in the github because the binary doesn't let you directly time fish functions. You can do time fish -c '[function]' but that includes the time to launch fish. This, of course, wouldn't matter for any reasonable usecase but I like a fancy prompt and don't like waiting for it to run.

Ah, timing other shell functions is a use case I hadn't considered. Yes, then you're out of luck I suppose.

I think $duration is a thing, which is the time it took to run the previous command. It doesn't separate things like time does, but it's still useful for some cases.

In fact, I customized my prompt to pretty print the previous command's duration if it took longer than 3 seconds or something like that.

Re: Fish shell 3.0

#218

Earlier quoted context omitted.

What does someone want if they write "bar = print foo,"? Is it the same if "print" isn't the built-in function?

That usage doesn't get the weirdly specific error message though. It's only the Python2-ish statement that gets one.

What does someone want "print foo" to do if "print" is a different function?

What does someone want "print (1, 2)" to do if "print" is the built-in function? It prints a tuple in Python 2 and ints in Python 3.

Re: Fish shell 3.0

#219
post #118

Earlier quoted context omitted.

It feels a bit more natural once you've bent your mind enough to understand what the shell is doing. The trick is that `test` and even `[` (which is essentially another name for `test`) are ordinary commands, that exist as stand-alone binaries as well as identical-behaving built-ins. They masquerade as syntax, but they're really not. You can even call them from other, non-shell languages: >>> from subprocess import r…

There are a few misfeatures in `test`, though. For instance, one way to use it is test somestring to test if "somestring" is empty. POSIX mandates that test with exactly one argument succeeds iff that argument is a non-empty string, to allow that. Fish's test is POSIX-conformant. Now, that means that test -n is true! Which is also triggered for test -n $var if $var has 0 elements. This is a problem and should be impr…

always quote your variables. POSIX won't change this soon, or likely ever.

Re: Fish shell 3.0

#220

Earlier quoted context omitted.

One thing I would add - using negative indices to index from end is a bad idea in general, because you may inadvertently end up with a negative index as a result of a calculation that you expected to always be positive - and then instead of an out-of-bounds error, you get silent wrong behavior. IMO, it's better to have dedicated syntax for index-from-end, as part of the range syntax. Again, Nim does that: x[0..^1] (a…

> IMO, it's better to have dedicated syntax for index-from-end, as part of the range syntax. This is true, and note that my suggestion requires it -- the only way to distinguish x[-0] from x[0] is to have the parser do it; -0 and 0 are the same number .

I mean, you could technically distinguish between positive and negative zero, if your numbers are all floating points (like JS or Lua). But that would be even more of a horror show.
Post reply on HN